from pydantic import BaseModel, Field
from typing import Literal

FormatType = Literal[
    "OnePager",
    "Cheatsheet",
    "MiniGuide",
    "Guide",
    "EndGuide",
]


class GuideCreateRequest(BaseModel):
    topic: str = Field(min_length=1, max_length=100)
    format: FormatType
    instructions: str = Field(default="", max_length=2000)
    reindex: bool = False


class ProjectResponse(BaseModel):
    name: str
    cached: bool


class GuideReworkRequest(BaseModel):
    instructions: str = Field(min_length=1, max_length=2000)


class GuideResponse(BaseModel):
    id: str
    topic: str
    format: str
    status: str
    progress: str | None = None
    error_msg: str | None = None
    created_at: str
    updated_at: str


class BausteinCreateRequest(BaseModel):
    topic: str = Field(min_length=1, max_length=100)
    title: str = Field(min_length=1, max_length=200)
    instructions: str = Field(default="", max_length=2000)


class BausteinReworkRequest(BaseModel):
    instructions: str = Field(min_length=1, max_length=2000)


class BausteinResponse(BaseModel):
    id: str
    topic: str
    title: str
    description: str
    purpose: str
    example: str
    sort_order: int = 0
    created_at: str
    updated_at: str


class BausteinSortRequest(BaseModel):
    instructions: str = Field(default="", max_length=2000)


class SuggestionResponse(BaseModel):
    id: str
    topic: str
    title: str
    description: str
    purpose: str
    example: str
    status: str
    created_at: str


class TopicSuggestRequest(BaseModel):
    problem: str = Field(min_length=1, max_length=2000)


class TopicSuggestion(BaseModel):
    title: str
    reason: str


class ChatMessage(BaseModel):
    role: Literal["user", "assistant"]
    content: str = Field(min_length=1, max_length=8000)


class GuideChatRequest(BaseModel):
    section: str = Field(default="", max_length=20000)
    outline: str = Field(default="", max_length=8000)
    messages: list[ChatMessage] = Field(min_length=1)


class GuideChatResponse(BaseModel):
    reply: str


class ProgressUpdate(BaseModel):
    chapter: str = Field(min_length=1, max_length=100)
    done: bool


class ProgressResponse(BaseModel):
    chapters: list[str]
