import { api, PageResponse } from '@/services/api';

export interface AbsenceDTO {
    id: string;
    agentId: string;
    startDate: string;
    endDate: string;
    days: number;
    reason?: string;
    justified: boolean;
}

export interface CreateAbsenceDTO {
    agentId: string;
    startDate: string; // YYYY-MM-DD
    endDate: string;   // YYYY-MM-DD
    reason?: string;
    justified: boolean;
}

export const absenceService = {
    create: async (data: CreateAbsenceDTO): Promise<AbsenceDTO> => {
        return api.post('/rh/absences', data);
    },

    findByAgent: async (
        agentId: string,
        page = 0,
        size = 20
    ): Promise<PageResponse<AbsenceDTO>> => {
        return api.getPage<AbsenceDTO>(`/rh/absences/agent/${agentId}`, {
            page,
            size,
        });
    },

    delete: async (id: string): Promise<void> => {
        return api.delete(`/rh/absences/${id}`);
    },
};
