"""
排期模型 — SQLModel
"""

from datetime import date, datetime

from sqlalchemy import Column
from sqlalchemy import DateTime as SADateTime
from sqlalchemy import Integer as SAInteger
from sqlalchemy import Date as SADate
from sqlalchemy import Text
from sqlalchemy.sql import func as sa_func
from sqlmodel import Field, SQLModel


class Schedule(SQLModel, table=True):
    __tablename__ = "schedules"

    id: int | None = Field(default=None, primary_key=True)
    episode_id: int | None = Field(default=None, foreign_key="episodes.id")
    planned_air_date: date
    status: str = Field(default="planned", max_length=20)
    editor_id: int | None = Field(default=None, foreign_key="users.id")
    notes: str | None = Field(default=None)

    created_at: datetime | None = Field(
        default=None,
        sa_column=Column(SADateTime(timezone=True), nullable=False, server_default=sa_func.now()),
    )
    updated_at: datetime | None = Field(
        default=None,
        sa_column=Column(SADateTime(timezone=True), nullable=False, server_default=sa_func.now()),
    )