from __future__ import annotations

from datetime import datetime

from pydantic import BaseModel, Field

from app.schemas.common import ErrorPayload


class CreateAgentSessionResponse(BaseModel):
    session_id: str
    active_rag_session_id: str | None = None
    created_at: datetime


class BindRagSessionRequest(BaseModel):
    rag_session_id: str = Field(min_length=1)


class BindRagSessionResponse(BaseModel):
    session_id: str
    active_rag_session_id: str | None = None
    updated_at: datetime


class ResetAgentSessionResponse(BaseModel):
    session_id: str
    active_rag_session_id: str | None = None
    status: str
    updated_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
    error: ErrorPayload | None = None
    created_at: datetime
    completed_at: datetime | None = None
