from __future__ import annotations

from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field

from app.schemas.common import ORMModel


class CreateSessionResponse(BaseModel):
    sessionId: int


class ChatSessionRead(ORMModel):
    model_config = ConfigDict(from_attributes=True, populate_by_name=True)

    id: int
    title: str
    messageCount: int = Field(alias="message_count")
    updatedAt: datetime = Field(alias="updated_at")


class ChatMessageRead(ORMModel):
    id: int
    topic_session_id: int | None = None
    role: str
    content: str
    message_status: str
    created_at: datetime


class UpdateSessionTitleRequest(BaseModel):
    sessionId: int
    title: str = Field(min_length=1, max_length=100)


class ChatCompletionRequest(BaseModel):
    sessionId: int
    message: str = Field(min_length=1, max_length=4000)
    retry: bool = False


class StopChatRequest(BaseModel):
    sessionId: int
