"""Pydantic schemas for MTG card data."""
from pydantic import BaseModel, ConfigDict
from typing import Optional, List
from datetime import datetime


class MtgCardResponse(BaseModel):
    """MTG card response."""
    id: int
    source_id: Optional[int]
    name: str
    mana_cost: Optional[str]
    type_line: Optional[str]
    oracle_text: Optional[str]
    power: Optional[str]
    toughness: Optional[str]
    rarity: Optional[str]
    layout: Optional[str]
    artist: Optional[str]
    flavor_text: Optional[str]
    numbers: Optional[str]
    identifiers: Optional[str]
    images: Optional[str]
    image: Optional[str]
    card_parts: Optional[str]
    keywords: Optional[str]
    legalities: Optional[str]
    set_code: Optional[str]
    set_name: Optional[str]
    synced_at: Optional[datetime]
    created_at: datetime
    
    model_config = ConfigDict(from_attributes=True)


class MtgCardSearchRequest(BaseModel):
    """MTG card search request."""
    query: str
    limit: int = 50
    offset: int = 0


class MtgCardSearchResponse(BaseModel):
    """MTG card search response."""
    cards: List[MtgCardResponse]
    total: int
    page: int
    page_size: int
    total_pages: int


class MtgSetResponse(BaseModel):
    """MTG set response."""
    id: int
    name: str
    code: str
    release_date: Optional[datetime]
    card_count: Optional[int]
    
    model_config = ConfigDict(from_attributes=True)


class MtgCardMirrorResponse(BaseModel):
    """Mirrored card data response."""
    id: int
    source_id: Optional[int]
    name: str
    mana_cost: Optional[str]
    type_line: Optional[str]
    oracle_text: Optional[str]
    power: Optional[str]
    toughness: Optional[str]
    rarity: Optional[str]
    layout: Optional[str]
    artist: Optional[str]
    flavor_text: Optional[str]
    numbers: Optional[str]
    identifiers: Optional[str]
    images: Optional[str]
    image: Optional[str]
    card_parts: Optional[str]
    keywords: Optional[str]
    legalities: Optional[str]
    set_code: Optional[str]
    set_name: Optional[str]
    synced_at: Optional[datetime]
    created_at: datetime
    
    model_config = ConfigDict(from_attributes=True)


class DeckCardLinkResponse(BaseModel):
    """Deck-card link response."""
    id: int
    deck_id: int
    card_id: int
    quantity: int
    zone: str
    card: MtgCardMirrorResponse
    
    model_config = ConfigDict(from_attributes=True)


class DeckWithCardsResponse(BaseModel):
    """Deck response with card links."""
    id: int
    name: str
    content: str
    format: str
    status: str
    folder_id: Optional[int]
    owner_id: int
    creation_date: datetime
    card_links: List[DeckCardLinkResponse] = []
    
    model_config = ConfigDict(from_attributes=True)
