"""客户端埋点上报 schema(批量)。

客户端把「设备固定维度」(device_id / user_id / oem / os / model / app_ver / channel / sent_at)
放批次外层只传一次,events 列表里每条只带「事件维度」(event / client_ts / session_id / page /
network / props);服务端展开成多行 AnalyticsEvent 落库(见 app/repositories/analytics.py)。
"""
from __future__ import annotations

from pydantic import BaseModel, Field


class AnalyticsEventIn(BaseModel):
    """单条事件维度。"""

    event: str = Field(max_length=64)
    client_ts: int = Field(description="端事件发生时间 epoch ms")
    session_id: str | None = Field(default=None, max_length=64)
    page: str | None = Field(default=None, max_length=64)
    network: str | None = Field(default=None, max_length=16)
    props: dict[str, str] = Field(default_factory=dict)


class AnalyticsBatchIn(BaseModel):
    """一批上报:公共维度 + 事件列表。"""

    # Who(整批共享)
    device_id: str = Field(max_length=64)
    user_id: int | None = None
    # When(本批上报时刻 epoch ms)
    sent_at: int | None = None
    # How(设备固定维度,整批共享)
    oem: str | None = Field(default=None, max_length=32)
    os: str | None = Field(default=None, max_length=32)
    model: str | None = Field(default=None, max_length=64)
    app_ver: str | None = Field(default=None, max_length=32)
    channel: str | None = Field(default=None, max_length=32)
    events: list[AnalyticsEventIn] = Field(min_length=1, max_length=200)


class AnalyticsIngestOut(BaseModel):
    ok: bool = True
    received: int
