from typing import Optional

from pydantic import BaseModel, Field, field_validator

ALLOWED_MIME_TYPES = {"application/pdf", "image/jpeg", "image/png", "image/tiff"}
ALLOWED_CATEGORIES = {"death_certificate", "burial_permit", "contract", "other"}


class DocumentUploadUrlRequest(BaseModel):
    filename: str = Field(..., min_length=1, max_length=500)
    mime_type: str = Field(..., description="Required MIME type")
    file_size_bytes: Optional[int] = Field(None, gt=0)
    category: Optional[str] = None

    @field_validator("mime_type")
    @classmethod
    def validate_mime_type(cls, v: str) -> str:
        if v not in ALLOWED_MIME_TYPES:
            raise ValueError(
                f"mime_type must be one of: {', '.join(sorted(ALLOWED_MIME_TYPES))}"
            )
        return v

    @field_validator("category")
    @classmethod
    def validate_category(cls, v: Optional[str]) -> Optional[str]:
        if v is not None and v not in ALLOWED_CATEGORIES:
            raise ValueError(
                "category must be one of: death_certificate, burial_permit, contract, other"
            )
        return v
