"""自报计数上报 schema。字段名对齐客户端 payload(snake_case),累计值语义。"""
from __future__ import annotations

from pydantic import BaseModel, Field


class SelfStatEventIn(BaseModel):
    event: str = Field(max_length=64)
    attempted: int = 0
    drop_capture: int = 0
    delivered: int = 0
    drop_undelivered: int = 0


class SelfStatBatchIn(BaseModel):
    device_id: str = Field(max_length=64)
    epoch_id: str = Field(max_length=64)
    sent_at: int | None = None
    app_ver: str | None = Field(default=None, max_length=32)
    oem: str | None = Field(default=None, max_length=32)
    os: str | None = Field(default=None, max_length=32)
    batches_attempted: int = 0
    batches_ok: int = 0
    batches_fail: int = 0
    retries: int = 0
    queue_depth: int = 0
    # 允许空列表:某次快照只上报设备级计数(batches_*/retries/queue_depth)、无 event 细分时也合法
    # (与 AnalyticsBatchIn 的 min_length=1 有意不同——那是行为事件、必须至少一条)。
    events: list[SelfStatEventIn] = Field(default_factory=list, max_length=200)


class SelfStatIngestOut(BaseModel):
    ok: bool = True
    snapshot_id: int
