from __future__ import annotations

from pathlib import Path
import sys

sys.path.insert(0, str(Path(__file__).resolve().parents[1]))

from financial_system.domain.models import EmployeeAttendance, PayrollResult
from financial_system.domain.payroll_exceptions import detect_payroll_exceptions


def test_detect_payroll_exceptions_flags_core_payroll_risks() -> None:
    result = PayrollResult(
        employee=EmployeeAttendance(name="张三", employee_no="ZA0001", department="生产中心"),
        salary_month="2026-06",
        salary_mode="monthly",
        attendance_days=0,
        absence_days=22,
        actual_work_hours=0,
        punch_overtime_hours=1,
        leave_hours=3,
        remaining_overtime_hours=-2,
        workday_overtime_hours=0,
        weekend_overtime_hours=0,
        holiday_overtime_hours=0,
        minor_late_count=4,
        major_late_count=1,
        penalized_late_count=2,
        late_deduction=60,
        missing_card_count=1,
        missing_card_deduction=20,
        total_deduction=80,
        base_salary=None,
        base_pay=None,
        commission_amount=0,
        overtime_rate=0,
        weekend_overtime_rate=0,
        holiday_overtime_rate=0,
        overtime_pay=0,
        gross_salary=None,
        net_salary=None,
        note="未配置薪资档案",
    )

    exception_types = {item.exception_type for item in detect_payroll_exceptions([result])}

    assert "missing_salary_profile" in exception_types
    assert "missing_card" in exception_types
    assert "late_penalty" in exception_types
    assert "negative_remaining_overtime" in exception_types
    assert "empty_attendance" in exception_types


if __name__ == "__main__":
    test_detect_payroll_exceptions_flags_core_payroll_risks()
