import { API } from '@/api/API';

export const resignationService = {
    getResignations: async () => {
        try {
            const response: any = await API.getResignations();
            return response.data;
        } catch (error) {
            console.error('Get resignations error:', error);
            throw error;
        }
    },
    createResignation: async (data: any) => {
        try {
            const response: any = await API.createResignation(data);
            return response.data;
        } catch (error) {
            console.error('Create resignation error:', error);
            throw error;
        }
    },
    getResignationById: async (id: string) => {
        try {
            const response: any = await API.getResignationById(id);
            return response.data?.resignation || response.data?.data || response.data;
        } catch (error) {
            console.error('Get resignation error:', error);
            throw error;
        }
    },
    updateClearance: async (id: string, data: any) => {
        try {
            const response: any = await API.updateClearance(id, data);
            return response.data;
        } catch (error) {
            console.error('Update clearance error:', error);
            throw error;
        }
    },
    uploadDocument: async (id: string, formData: FormData) => {
        try {
            const response: any = await API.uploadResignationDocument(id, formData);
            return response.data;
        } catch (error) {
            console.error('Upload resignation document error:', error);
            throw error;
        }
    },
    withdraw: async (id: string, reason: string) => {
        try {
            const response: any = await API.withdrawResignation(id, reason);
            return response.data;
        } catch (error) {
            console.error('Withdraw resignation error:', error);
            throw error;
        }
    }
};
