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


class SpreadBetCreate(BaseModel):
    event_id: int
    spread: float
    team: TeamSide
    stake_amount: Decimal


class SpreadBetTake(BaseModel):
    pass


class SpreadBet(BaseModel):
    id: int
    event_id: int
    spread: float
    team: TeamSide
    creator_id: int
    taker_id: Optional[int] = None
    stake_amount: Decimal
    house_commission_percent: Decimal
    status: SpreadBetStatus
    payout_amount: Optional[Decimal] = None
    winner_id: Optional[int] = None
    created_at: datetime
    matched_at: Optional[datetime] = None
    completed_at: Optional[datetime] = None

    class Config:
        from_attributes = True


class SpreadBetDetail(SpreadBet):
    creator_username: str
    taker_username: Optional[str] = None
    event_home_team: str
    event_away_team: str
    event_official_spread: float
    event_game_time: datetime
