"""admin 大盘 schemas(对应 stats.dashboard_overview 的嵌套结构)。"""
from __future__ import annotations

from datetime import date

from pydantic import BaseModel


class DashboardUsers(BaseModel):
    total: int
    active: int
    disabled: int
    deleted: int
    new_today: int
    dau: int


class DashboardCoins(BaseModel):
    reward_video_coin_total: int = 0
    reward_video_watch_count: int = 0
    feed_ad_coin_total: int = 0
    feed_ad_watch_count: int = 0
    signin_coin_total: int = 0
    signin_count: int = 0
    signin_boost_coin_total: int = 0
    signin_boost_watch_count: int = 0
    granted_total: int


class DashboardCash(BaseModel):
    withdraw_success_cents: int
    withdraw_pending_count: int
    withdraw_success_count: int
    withdraw_failed_count: int


class DashboardComparison(BaseModel):
    total: int
    success: int
    success_rate: float


class DashboardPeriodUsers(BaseModel):
    new: int
    active: int
    retained_new_users: int
    retention_rate: float | None = None
    retention_note: str


class DashboardPeriodComparison(BaseModel):
    total: int
    success: int
    success_rate: float
    ordered: int
    average_duration_ms: int | None = None
    average_saved_cents: int | None = None


class DashboardPeriodCoins(BaseModel):
    granted_total: int
    reward_video_coin_total: int = 0
    feed_ad_coin_total: int = 0
    signin_coin_total: int = 0
    signin_boost_coin_total: int = 0
    task_coin_total: int = 0
    coupon_reward_coin_total: int = 0
    comparison_reward_coin_total: int = 0
    regular_task_coin_total: int = 0


class DashboardPeriodCash(BaseModel):
    withdraw_success_cents: int


class DashboardTrendPoint(BaseModel):
    date: date
    active_users: int
    new_users: int
    comparisons: int


class DashboardPeriod(BaseModel):
    date_from: date
    date_to: date
    users: DashboardPeriodUsers
    comparison: DashboardPeriodComparison
    coins: DashboardPeriodCoins
    cash: DashboardPeriodCash
    trend: list[DashboardTrendPoint] = []


class DashboardFeedback(BaseModel):
    new: int


class DashboardCps(BaseModel):
    available: bool
    note: str
    meituan_order_count: int = 0
    meituan_commission_cents: int = 0
    meituan_hit_count: int = 0
    meituan_miss_count: int = 0
    meituan_unknown_rate_count: int = 0
    meituan_hit_rate: float | None = None


class DashboardOverview(BaseModel):
    users: DashboardUsers
    coins: DashboardCoins
    cash: DashboardCash
    comparison: DashboardComparison
    period: DashboardPeriod
    feedback: DashboardFeedback
    cps: DashboardCps
