from __future__ import annotations

from datetime import datetime

from sqlalchemy import Boolean, DateTime, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column

from .base import Base


class MatchSchedule(Base):
    """SQLAlchemy ORM model for MatchSchedules"""

    __tablename__ = "MatchSchedule"

    # Primary Key - using UniqueMatch as primary key
    UniqueMatch: Mapped[str] = mapped_column(String, primary_key=True)

    # Basic Information
    OverviewPage: Mapped[str | None] = mapped_column(String, default=None)
    ShownName: Mapped[str | None] = mapped_column(String, default=None)
    ShownRound: Mapped[str | None] = mapped_column(Text, default=None)

    # Team Information
    Team1: Mapped[str | None] = mapped_column(String, default=None)
    Team2: Mapped[str | None] = mapped_column(String, default=None)
    Team1Final: Mapped[str | None] = mapped_column(String, default=None)
    Team2Final: Mapped[str | None] = mapped_column(String, default=None)
    Winner: Mapped[str | None] = mapped_column(String, default=None)
    Team1Poster: Mapped[str | None] = mapped_column(String, default=None)
    Team2Poster: Mapped[str | None] = mapped_column(String, default=None)
    PageAndTeam1: Mapped[str | None] = mapped_column(String, default=None)
    PageAndTeam2: Mapped[str | None] = mapped_column(String, default=None)

    # Player Information (for 1v1 matches)
    Player1: Mapped[str | None] = mapped_column(String, default=None)
    Player2: Mapped[str | None] = mapped_column(String, default=None)

    # Score Information
    Team1Points: Mapped[int | None] = mapped_column(Integer, default=None)
    Team2Points: Mapped[int | None] = mapped_column(Integer, default=None)
    Team1PointsTB: Mapped[int | None] = mapped_column(Integer, default=None)
    Team2PointsTB: Mapped[int | None] = mapped_column(Integer, default=None)
    Team1Score: Mapped[int | None] = mapped_column(Integer, default=None)
    Team2Score: Mapped[int | None] = mapped_column(Integer, default=None)
    Team1Advantage: Mapped[int | None] = mapped_column(Integer, default=None)
    Team2Advantage: Mapped[int | None] = mapped_column(Integer, default=None)

    # Match Status
    FF: Mapped[int | None] = mapped_column(Integer, default=None)
    IsNullified: Mapped[bool | None] = mapped_column(Boolean, default=None)

    # DateTime and Scheduling
    MatchDay: Mapped[int | None] = mapped_column(Integer, default=None)
    DateTime_UTC: Mapped[datetime | None] = mapped_column(DateTime, default=None)
    HasTime: Mapped[bool | None] = mapped_column(Boolean, default=None)
    DST: Mapped[str | None] = mapped_column(String, default=None)
    IsFlexibleStart: Mapped[bool | None] = mapped_column(Boolean, default=None)
    IsReschedulable: Mapped[bool | None] = mapped_column(Boolean, default=None)

    # Predictions
    OverrideAllowPredictions: Mapped[bool | None] = mapped_column(Boolean, default=None)
    OverrideDisallowPredictions: Mapped[bool | None] = mapped_column(
        Boolean, default=None
    )

    # Tournament Structure
    BestOf: Mapped[int | None] = mapped_column(Integer, default=None)
    Round: Mapped[str | None] = mapped_column(String, default=None)
    Phase: Mapped[str | None] = mapped_column(String, default=None)
    GroupName: Mapped[str | None] = mapped_column(String, default=None)
    IsTiebreaker: Mapped[bool | None] = mapped_column(Boolean, default=None)

    # Navigation/Indexing
    N_MatchInPage: Mapped[int | None] = mapped_column(Integer, default=None)
    Tab: Mapped[str | None] = mapped_column(String, default=None)
    N_MatchInTab: Mapped[int | None] = mapped_column(Integer, default=None)
    N_TabInPage: Mapped[int | None] = mapped_column(Integer, default=None)
    N_Page: Mapped[int | None] = mapped_column(Integer, default=None)
    InitialN_MatchInTab: Mapped[int | None] = mapped_column(Integer, default=None)
    InitialPageAndTab: Mapped[str | None] = mapped_column(String, default=None)

    # Patch Information
    Patch: Mapped[str | None] = mapped_column(String, default=None)
    LegacyPatch: Mapped[str | None] = mapped_column(String, default=None)
    PatchPage: Mapped[str | None] = mapped_column(String, default=None)
    Hotfix: Mapped[str | None] = mapped_column(String, default=None)
    DisabledChampions: Mapped[str | None] = mapped_column(
        String, default=None
    )  # Comma-delimited list
    PatchFootnote: Mapped[str | None] = mapped_column(Text, default=None)

    # Broadcast Information
    Stream: Mapped[str | None] = mapped_column(Text, default=None)  # Wikitext
    StreamDisplay: Mapped[str | None] = mapped_column(Text, default=None)
    Venue: Mapped[str | None] = mapped_column(String, default=None)
    CastersPBP: Mapped[str | None] = mapped_column(Text, default=None)
    CastersColor: Mapped[str | None] = mapped_column(Text, default=None)
    Casters: Mapped[str | None] = mapped_column(
        String, default=None
    )  # Comma-delimited list

    # MVP and Content
    MVP: Mapped[str | None] = mapped_column(String, default=None)
    MVPPoints: Mapped[int | None] = mapped_column(Integer, default=None)
    VodInterview: Mapped[str | None] = mapped_column(Text, default=None)  # Wikitext
    VodHighlights: Mapped[str | None] = mapped_column(Text, default=None)  # Wikitext
    InterviewWith: Mapped[str | None] = mapped_column(
        String, default=None
    )  # Comma-delimited list
    Recap: Mapped[str | None] = mapped_column(Text, default=None)
    Reddit: Mapped[str | None] = mapped_column(Text, default=None)

    # External IDs
    QQ: Mapped[int | None] = mapped_column(Integer, default=None)
    Wanplus: Mapped[str | None] = mapped_column(String, default=None)
    WanplusId: Mapped[int | None] = mapped_column(Integer, default=None)
    MatchId: Mapped[str | None] = mapped_column(String, default=None)

    # Footnotes and Tags
    Team1Footnote: Mapped[str | None] = mapped_column(Text, default=None)
    Team2Footnote: Mapped[str | None] = mapped_column(Text, default=None)
    Footnote: Mapped[str | None] = mapped_column(Text, default=None)
    Tags: Mapped[str | None] = mapped_column(
        String, default=None
    )  # Comma-delimited list
