from pydantic import BaseModel, Field
from datetime import datetime
from decimal import Decimal
from app.models.spread_bet import SpreadBetStatus, TeamSide


# Spread Bet Schemas

class SpreadBetCreate(BaseModel):
    """Schema for creating a spread bet"""
    event_id: int
    spread: float
    team: TeamSide
    stake_amount: Decimal = Field(..., gt=0, decimal_places=2)


class SpreadBetTake(BaseModel):
    """Schema for taking a spread bet (no body needed, bet_id in URL)"""
    pass


class SpreadBet(BaseModel):
    """Schema for returning spread bet"""
    id: int
    event_id: int
    spread: float
    team: TeamSide
    creator_id: int
    taker_id: int | None
    stake_amount: Decimal
    house_commission_percent: Decimal
    status: SpreadBetStatus
    winner_id: int | None
    settled_at: datetime | None
    payout_to_winner: Decimal | None
    house_fee_collected: Decimal | None
    created_at: datetime
    matched_at: datetime | None
    updated_at: datetime

    class Config:
        from_attributes = True


class SpreadBetDetail(SpreadBet):
    """Detailed spread bet with creator/taker info"""
    creator_username: str
    taker_username: str | None
    event_home_team: str
    event_away_team: str
    event_official_spread: float
    event_game_time: datetime

    class Config:
        from_attributes = True


class SpreadBetSettle(BaseModel):
    """Schema for settling a spread bet"""
    winner_id: int
