import { api } from './api';
import { MonthlyAttendanceSheetDTO, AttendanceRecordDTO } from '@/types/attendance';

export const attendanceService = {
    getSheet: (orgUnitId: string, month: number, year: number): Promise<MonthlyAttendanceSheetDTO> =>
        api.get('/rh/attendance/sheet', { params: { orgUnitId, month, year } }),

    getRecords: (sheetId: string): Promise<AttendanceRecordDTO[]> =>
        api.get(`/rh/attendance/sheet/${sheetId}/records`),

    approveSheet: (sheetId: string): Promise<void> =>
        api.post(`/rh/attendance/sheet/${sheetId}/approve`),

    reopenSheet: (sheetId: string): Promise<void> =>
        api.post(`/rh/attendance/sheet/${sheetId}/reopen`),

    uploadExcel: async (sheetId: string, file: File): Promise<void> => {
        const formData = new FormData();
        formData.append('file', file);
        await api.post(`/rh/attendance/sheet/${sheetId}/upload`, formData, {
            headers: {
                'Content-Type': 'multipart/form-data',
            },
        });
    },
};
