from typing import Optional

from pydantic import BaseModel, ConfigDict


class DocumentUploadUrlResponse(BaseModel):
    document_id: str                # UUID
    upload_url: str                 # presigned S3 POST URL
    upload_fields: dict[str, str]   # form fields required for the multipart POST


class DocumentResponse(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: str
    filename: str
    mime_type: Optional[str] = None
    file_size_bytes: Optional[int] = None
    category: Optional[str] = None
    created_at: str  # ISO string

    @classmethod
    def from_orm_doc(cls, doc) -> "DocumentResponse":
        return cls(
            id=str(doc.id),
            filename=doc.filename,
            mime_type=doc.mime_type,
            file_size_bytes=doc.file_size_bytes,
            category=doc.category,
            created_at=doc.created_at.isoformat(),
        )
