from pydantic import BaseModel, Field
from datetime import datetime
from decimal import Decimal
from app.models.sport_event import SportType, EventStatus


# Sport Event Schemas

class SportEventBase(BaseModel):
    sport: SportType
    home_team: str = Field(..., min_length=1, max_length=100)
    away_team: str = Field(..., min_length=1, max_length=100)
    official_spread: float
    game_time: datetime
    venue: str | None = None
    league: str | None = None
    min_spread: float = -10.0
    max_spread: float = 10.0
    min_bet_amount: float = 10.0
    max_bet_amount: float = 1000.0


class SportEventCreate(SportEventBase):
    """Schema for admin creating a new sport event"""
    pass


class SportEventUpdate(BaseModel):
    """Schema for admin updating event details"""
    sport: SportType | None = None
    home_team: str | None = None
    away_team: str | None = None
    official_spread: float | None = None
    game_time: datetime | None = None
    venue: str | None = None
    league: str | None = None
    status: EventStatus | None = None
    final_score_home: int | None = None
    final_score_away: int | None = None
    min_spread: float | None = None
    max_spread: float | None = None
    min_bet_amount: float | None = None
    max_bet_amount: float | None = None


class SportEvent(SportEventBase):
    """Schema for returning sport event"""
    id: int
    status: EventStatus
    final_score_home: int | None
    final_score_away: int | None
    created_by: int
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True


class SportEventWithBets(SportEvent):
    """Sport event with spread grid information"""
    spread_grid: dict[str, dict]  # spread value -> bet info
    # Example: {
    #   "-3.0": {"bet_id": 5, "creator": "Alice", "stake": 100.00, "status": "open"},
    #   "3.0": null,  # No bet at this spread
    # }

    class Config:
        from_attributes = True
