from datetime import datetime

from pydantic import BaseModel, ConfigDict, field_validator


class SectorConfig(BaseModel):
    sector_name: str
    rows: int
    seats_per_row: int
    price: int

    @field_validator("rows", "seats_per_row", "price")
    @classmethod
    def must_be_positive(cls, v: int) -> int:
        if v <= 0:
            raise ValueError("Must be a positive integer")
        return v


class SeatGenerateRequest(BaseModel):
    sectors: list[SectorConfig]


class TournamentCreate(BaseModel):
    title: str
    description: str | None = None
    event_date: datetime


class TournamentResponse(BaseModel):
    id: int
    title: str
    description: str | None
    event_date: datetime

    model_config = ConfigDict(from_attributes=True)


class SeatResponse(BaseModel):
    id: int
    sector: str
    row: int
    number: int
    price: int
    is_available: bool
