from __future__ import annotations

from datetime import datetime

from pydantic import BaseModel

from .payroll import PayrollResultDTO


class MonthlyPayrollCreateRequest(BaseModel):
    """月度核算创建请求，用于钉钉计算。"""

    salary_month: str
    source_type: str = "dingtalk"
    export_excel: bool = True


class MonthlyPayrollRunResponse(BaseModel):
    """月度核算批次响应。"""

    id: int
    salary_month: str
    source_type: str
    source_job_id: str
    status: str
    employee_count: int
    gross_total: float
    net_total: float
    deduction_total: float
    overtime_total: float
    locked_by: str
    locked_at: datetime | None
    created_by: str
    created_at: datetime
    updated_at: datetime


class PayrollExceptionItem(BaseModel):
    """月度核算异常响应。"""

    id: int
    run_id: int | None
    sync_job_id: str | None
    employee_id: int | None
    employee_no: str
    employee_name: str
    salary_month: str
    exception_type: str
    severity: str
    message: str
    status: str
    created_at: datetime
    resolved_at: datetime | None


class MonthlyPayrollDetailResponse(BaseModel):
    """月度核算批次详情。"""

    run: MonthlyPayrollRunResponse
    results: list[PayrollResultDTO]
    exceptions: list[PayrollExceptionItem]
