"""admin 首页三统计展示配置 schemas。

倍率用千分比整数(1.000→1000);total_saved 的 manual_value / random_current 单位是分。
"""
from __future__ import annotations

from pydantic import BaseModel


class OpsStatItemOut(BaseModel):
    metric: str  # help_users / total_compares / total_saved
    label: str  # 帮助用户 / 完成比价 / 累计节省
    unit: str  # 人 / 次 / 分
    mode: str  # real / manual / random
    manual_value: int | None = None
    random_mult_min: int
    random_mult_max: int
    random_tick_seconds: int
    random_anchor_minutes: int
    random_kind: str  # mult(×倍率) / add(+绝对增量)
    random_step_min: int  # 绝对增量区间(基础单位;total_saved 为分)
    random_step_max: int
    real_offset: int  # 真实值模式保底值(基础单位):展示=max(真实,保底)。列名沿用 real_offset
    allow_decrease: bool  # 是否允许展示值下降(默认 false = 只增不减)
    random_current: int | None = None
    random_last_tick_at: str | None = None
    real_value: int  # 当前真实值(纯真实、不含偏移;给运营对比参考)
    updated_at: str | None = None


class OpsStatUpdateRequest(BaseModel):
    """改某指标配置(均可选,只改传了的字段)。"""

    mode: str | None = None
    manual_value: int | None = None
    random_mult_min: int | None = None
    random_mult_max: int | None = None
    random_tick_seconds: int | None = None
    random_anchor_minutes: int | None = None
    random_kind: str | None = None  # mult / add
    random_step_min: int | None = None
    random_step_max: int | None = None
    real_offset: int | None = None
    allow_decrease: bool | None = None
    # 切 random 时的初始基数;不传则用当前真实值播种
    random_initial: int | None = None
    # 立即更新:不等更新钟点,保存后马上把展示值刷新一次(real 快照/manual 生效/random 走一档)
    apply_now: bool = False
