import { beforeEach, describe, expect, it, vi } from 'vitest';
import {
  getStaffAttendanceSummary,
  listStaffAttendanceRecords,
} from '@/shared/api/staffAttendance';
import { apiRequest } from '@/shared/api/httpClient';

vi.mock('@/shared/api/httpClient', () => ({
  apiRequest: vi.fn(),
}));

const apiRequestMock = vi.mocked(apiRequest);

describe('staff attendance API', () => {
  beforeEach(() => {
    apiRequestMock.mockReset();
  });

  it('lists records without query parameters when no filter is provided', () => {
    void listStaffAttendanceRecords();

    expect(apiRequestMock).toHaveBeenCalledWith('/staff_attendance/records');
  });

  it('lists records with date and limit filters', () => {
    void listStaffAttendanceRecords({
      startDate: '2026-06-08',
      endDate: '2026-06-12',
      limit: 25,
    });

    expect(apiRequestMock).toHaveBeenCalledWith(
      '/staff_attendance/records?startDate=2026-06-08&endDate=2026-06-12&limit=25',
    );
  });

  it('gets summary with the same filter contract as records', () => {
    void getStaffAttendanceSummary({
      startDate: '2026-06-08',
      endDate: '2026-06-12',
    });

    expect(apiRequestMock).toHaveBeenCalledWith(
      '/staff_attendance/summary?startDate=2026-06-08&endDate=2026-06-12',
    );
  });
});
