from pydantic import BaseModel, ConfigDict, Field


class OrderReportRequest(BaseModel):
    """客户端归因成功后的上报体。金额一律用「分」(int) 传，避免浮点误差。"""

    client_event_id: str = Field(..., max_length=64, description="客户端幂等键(UUID)")
    platform: str = Field(..., max_length=32, description="平台展示名,如 美团")
    platform_package: str | None = Field(None, max_length=128, description="平台包名")
    pay_channel: str = Field(..., max_length=16, description="支付渠道 wechat/alipay")
    compared_price_cents: int = Field(..., ge=0, description="我们给出的比价价(分)")
    paid_amount_cents: int = Field(..., ge=0, description="实际支付金额(分)")
    device_id: str | None = Field(None, max_length=128)
    # ===== 比价时携带的记账信息(客户端从意图识别阶段缓存而来;旧版客户端可能不传,故全部可空)=====
    shop_name: str | None = Field(None, max_length=128, description="门店名,如 肯德基宅急送（天北路店）")
    dishes: list[str] = Field(default_factory=list, description="菜品名列表")
    original_price_cents: int | None = Field(None, ge=0, description="源平台原价(分),省额=原价−实付")
    source_platform_name: str | None = Field(None, max_length=32, description="源平台展示名,如 美团")
    source_deeplink: str | None = Field(None, max_length=512, description="源平台重进链接(预留,本期只存不展示)")


class OrderReportOut(BaseModel):
    model_config = ConfigDict(from_attributes=True)

    id: int
    platform: str
    pay_channel: str
    compared_price_cents: int
    paid_amount_cents: int
    duplicated: bool = False
