"""Tag schemas for Phase 5."""

from __future__ import annotations

from datetime import datetime
from typing import List, Optional

from pydantic import BaseModel, Field


class TagResponse(BaseModel):
    """Tag response schema."""

    id: int
    tag_name: str
    created_date: datetime

    class Config:
        from_attributes = True


class TagCreateRequest(BaseModel):
    """Request to create a tag."""

    tag_name: str = Field(..., description="Tag name")


class TagsResponse(BaseModel):
    """Response for listing tags."""

    items: List[TagResponse]
    total: int


class PhotoTagsRequest(BaseModel):
    """Request to add/remove tags from photos."""

    photo_ids: List[int] = Field(..., description="Photo IDs")
    tag_names: List[str] = Field(..., description="Tag names to add/remove")


class PhotoTagsResponse(BaseModel):
    """Response for photo tagging operations."""

    message: str
    photos_updated: int
    tags_added: int
    tags_removed: int


class TagUpdateRequest(BaseModel):
    """Request to update a tag name."""

    tag_name: str = Field(..., description="New tag name")


class TagDeleteRequest(BaseModel):
    """Request to delete tags."""

    tag_ids: List[int] = Field(..., description="Tag IDs to delete")


class PhotoTagItem(BaseModel):
    """Tag item for a photo."""

    tag_id: int
    tag_name: str


class PhotoTagsListResponse(BaseModel):
    """Response for listing tags on a photo."""

    photo_id: int
    tags: List[PhotoTagItem]
    total: int


class PhotoWithTagsItem(BaseModel):
    """Photo item with tags for tag manager."""

    id: int
    filename: str
    path: str
    processed: bool
    date_taken: Optional[str] = None
    date_added: Optional[str] = None
    face_count: int
    unidentified_face_count: int  # Count of faces with person_id IS NULL
    tags: str  # Comma-separated tags string (matching desktop)
    people_names: str = ""  # Comma-separated people names string


class PhotosWithTagsResponse(BaseModel):
    """Response for listing photos with tags."""

    items: List[PhotoWithTagsItem]
    total: int

