// Read-only HRM reports (docs/13-BACKEND-HRM-API.md §6, FR-HR-RPT).
import { apiRequest, buildQuery } from "@/lib/api-client"
import {
  AttendanceSummaryRow,
  DocumentExpiryReportRow,
  LateArrivalReportRow,
  LeaveBalanceReportRow,
  OvertimeReportRow,
  PayrollRegisterRow,
  SalaryHistoryRow,
} from "@/types/hrm"

export const hrReportsApi = {
  attendanceSummary(periodYear: number, periodMonth: number, departmentId?: number): Promise<AttendanceSummaryRow[]> {
    return apiRequest<AttendanceSummaryRow[]>(`/reports/hrm/attendance-summary${buildQuery({ periodYear, periodMonth, departmentId })}`)
  },
  overtime(periodYear: number, periodMonth: number): Promise<OvertimeReportRow[]> {
    return apiRequest<OvertimeReportRow[]>(`/reports/hrm/overtime${buildQuery({ periodYear, periodMonth })}`)
  },
  lateArrivals(periodYear: number, periodMonth: number): Promise<LateArrivalReportRow[]> {
    return apiRequest<LateArrivalReportRow[]>(`/reports/hrm/late-arrivals${buildQuery({ periodYear, periodMonth })}`)
  },
  payrollRegister(payrollRunId: number): Promise<PayrollRegisterRow[]> {
    return apiRequest<PayrollRegisterRow[]>(`/reports/hrm/payroll-register${buildQuery({ payrollRunId })}`)
  },
  salaryHistory(employeeId: number): Promise<SalaryHistoryRow[]> {
    return apiRequest<SalaryHistoryRow[]>(`/reports/hrm/salary-history${buildQuery({ employeeId })}`)
  },
  leaveBalances(year: number): Promise<LeaveBalanceReportRow[]> {
    return apiRequest<LeaveBalanceReportRow[]>(`/reports/hrm/leave-balances${buildQuery({ year })}`)
  },
  documentExpiry(withinDays: number): Promise<DocumentExpiryReportRow[]> {
    return apiRequest<DocumentExpiryReportRow[]>(`/reports/hrm/document-expiry${buildQuery({ withinDays })}`)
  },
}
