"""
年度收视目标 Schema — 请求 / 响应模型

业务规则：yearly_targets 只增不改，ON CONFLICT DO NOTHING
"""

from datetime import date

from pydantic import BaseModel, ConfigDict


class YearlyTargetBase(BaseModel):
    year: int
    base_target: float
    stretch_target: float
    issued_date: date | None = None
    notes: str | None = None


class YearlyTargetCreate(YearlyTargetBase):
    pass


class YearlyTargetUpdate(BaseModel):
    """PATCH 时允许只传部分字段，year 不可修改（由 API 层 pop 掉）。"""
    year: int | None = None
    base_target: float | None = None
    stretch_target: float | None = None
    issued_date: date | None = None
    notes: str | None = None


class YearlyTargetResponse(YearlyTargetBase):
    id: int

    model_config = ConfigDict(from_attributes=True)