from __future__ import annotations

from datetime import date
from pathlib import Path
import sys

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

from financial_system.services.realtime_attendance_service import TodayAttendanceItemData, build_realtime_summary


def test_build_realtime_summary_counts_today_status() -> None:
    items = [
        TodayAttendanceItemData(
            employee_id=1,
            employee_no="ZA0001",
            employee_name="张三",
            department="生产中心",
            position="技工",
            first_punch="08:58",
            last_punch="18:30",
            attendance_status="present",
            late_minutes=0,
            missing_card_count=0,
            leave_hours=0,
            today_overtime_hours=1,
            month_remaining_overtime_hours=4,
            estimated_net_salary=6800,
            note="",
        ),
        TodayAttendanceItemData(
            employee_id=2,
            employee_no="ZA0002",
            employee_name="李四",
            department="行政人事部",
            position="人事专员",
            first_punch="09:08",
            last_punch="",
            attendance_status="missing",
            late_minutes=8,
            missing_card_count=1,
            leave_hours=2,
            today_overtime_hours=0,
            month_remaining_overtime_hours=-2,
            estimated_net_salary=None,
            note="缺少下班卡",
        ),
        TodayAttendanceItemData(
            employee_id=3,
            employee_no="ZA0003",
            employee_name="王五",
            department="财务部",
            position="财务",
            first_punch="",
            last_punch="",
            attendance_status="unchecked",
            late_minutes=0,
            missing_card_count=0,
            leave_hours=0,
            today_overtime_hours=0,
            month_remaining_overtime_hours=0,
            estimated_net_salary=5000,
            note="",
        ),
    ]

    summary = build_realtime_summary(date(2026, 6, 22), items)

    assert summary.employee_total == 3
    assert summary.checked_in_count == 2
    assert summary.unchecked_count == 1
    assert summary.late_count == 1
    assert summary.leave_count == 1
    assert summary.missing_card_count == 1
    assert summary.estimated_overtime_count == 1
    assert summary.estimated_net_total == 11800


if __name__ == "__main__":
    test_build_realtime_summary_counts_today_status()
