from __future__ import annotations

from datetime import datetime

from pydantic import BaseModel, Field

from app.schemas.indexing import FileSnapshot, IndexJobStatus
from app.schemas.changeset import ChangeItem
from app.schemas.common import ErrorPayload


class CreateAgentSessionRequest(BaseModel):
    project_id: str = Field(min_length=1)
    files: list[FileSnapshot]


class CreateAgentSessionResponse(BaseModel):
    session_id: str
    rag_session_id: str = Field(min_length=1)
    index_job_id: str = Field(min_length=1)
    status: IndexJobStatus
    created_at: datetime


class AgentRequestCreateRequest(BaseModel):
    session_id: str = Field(min_length=1)
    message: str = Field(min_length=1)
    process_version: str = Field(default="v1", min_length=1)


class AgentRequestQueuedResponse(BaseModel):
    request_id: str
    session_id: str
    status: str
    stream_url: str


class AgentRequestStateResponse(BaseModel):
    request_id: str
    session_id: str
    status: str
    process_version: str
    answer: str | None = None
    changeset: list[ChangeItem] = Field(default_factory=list)
    apply_changeset: bool = False
    error: ErrorPayload | None = None
    created_at: datetime
    completed_at: datetime | None = None
