"""Pydantic request/response models for BadNote."""

from pydantic import BaseModel, Field


# ── Auth ────────────────────────────────────────────────────────────────────

class UserCreate(BaseModel):
    username: str = Field(..., min_length=1, max_length=64)
    password: str = Field(..., min_length=4, max_length=128)


class UserLogin(BaseModel):
    username: str
    password: str


class TokenResponse(BaseModel):
    token: str
    user_id: str


# ── Notes ───────────────────────────────────────────────────────────────────

class NoteCreate(BaseModel):
    id: str
    title: str = ""
    tags: list[str] = Field(default_factory=list)
    strokes_json: str = "[]"


class NoteUpdate(BaseModel):
    title: str | None = None
    tags: list[str] | None = None
    strokes_json: str | None = None


class NoteResponse(BaseModel):
    id: str
    user_id: str
    title: str
    created_at: str
    updated_at: str
    tags: list[str]
    strokes_json: str


# ── Documents ───────────────────────────────────────────────────────────────

class DocumentResponse(BaseModel):
    id: str
    user_id: str
    filename: str
    doc_type: str
    page_count: int
    created_at: str
    updated_at: str


class AnnotationUpdate(BaseModel):
    annotation_json: list[dict] = Field(default_factory=list)


class AnnotationResponse(BaseModel):
    id: str
    document_id: str
    page_number: int
    annotation_json: list[dict]
    created_at: str
    updated_at: str


class BookmarkCreate(BaseModel):
    page_number: int
    label: str = ""
    color: int = 4283215696


class BookmarkResponse(BaseModel):
    id: str
    document_id: str
    page_number: int
    label: str
    color: int
    created_at: str


# ── OCR ─────────────────────────────────────────────────────────────────────

class OcrJobRequest(BaseModel):
    note_id: str | None = None
    document_id: str | None = None
    page_number: int | None = None


class OcrJobStatus(BaseModel):
    id: str
    status: str
    result_text: str | None = None
    error_message: str | None = None
    created_at: str
    completed_at: str | None = None


class OcrResult(BaseModel):
    id: str
    note_id: str | None
    document_id: str | None
    page_number: int | None
    status: str
    result_text: str | None
    error_message: str | None
    created_at: str
    completed_at: str | None


# ── Sync ────────────────────────────────────────────────────────────────────

class SyncNote(BaseModel):
    id: str
    title: str = ""
    tags: list[str] = Field(default_factory=list)
    strokes_json: str = "[]"
    updated_at: str


class SyncPushRequest(BaseModel):
    notes: list[SyncNote]


class SyncPullRequest(BaseModel):
    since: str


class SyncResponse(BaseModel):
    synced_count: int
