from __future__ import annotations

from datetime import datetime

from pydantic import BaseModel, ConfigDict, Field


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

    relation_type: str


class ArchivedApplicationRead(BaseModel):
    """付款事件中允许用户看到的关联申请摘要。"""

    model_config = ConfigDict(extra="ignore")

    application_claim_no: str = ""


class BusinessEventPayloadRead(BaseModel):
    """费用时间线允许面向用户展示的事件载荷。"""

    model_config = ConfigDict(extra="ignore")

    previous_status: str = ""
    next_status: str = ""
    next_approval_stage: str = ""
    reason: str = ""
    opinion: str = ""
    message: str = ""
    application_claim_no: str = ""
    reimbursement_claim_no: str = ""
    claim_no: str = ""
    file_name: str = ""
    document_type: str = ""
    scene_code: str = ""
    review_status: str = ""
    passed: bool | None = None
    blocking_risk_count: int = 0
    business_stage: str = ""
    archived_applications: list[ArchivedApplicationRead] = Field(default_factory=list)


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

    id: str
    event_type: str
    actor_id: str
    actor_type: str
    payload_json: BusinessEventPayloadRead = Field(default_factory=BusinessEventPayloadRead)
    occurred_at: datetime


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

    id: str
    case_no: str
    current_stage: str
    status: str
    links: list[ExpenseCaseLinkRead] = Field(default_factory=list)
    events: list[BusinessEventRead] = Field(default_factory=list)
