import { api } from './api';
import {
    SalaryCategoryDTO,
    SalaryGradeDTO,
    SalaryStepDTO,
    SalaryGridDTO,
    SalaryStructureFullDTO
} from '@/types/salary';

const BASE_URL = '/rh/salary-structure';

export const salaryService = {
    // Categories
    getAllCategories: async (): Promise<SalaryCategoryDTO[]> => {
        return await api.get<SalaryCategoryDTO[]>(`${BASE_URL}/categories`);
    },
    createCategory: async (data: any): Promise<SalaryCategoryDTO> => {
        return await api.post<SalaryCategoryDTO>(`${BASE_URL}/categories`, data);
    },
    updateCategory: async (id: string, data: any): Promise<SalaryCategoryDTO> => {
        return await api.put<SalaryCategoryDTO>(`${BASE_URL}/categories/${id}`, data);
    },
    deleteCategory: async (id: string): Promise<void> => {
        await api.delete(`${BASE_URL}/categories/${id}`);
    },

    // Grades
    getGradesByCategory: async (categoryId: string): Promise<SalaryGradeDTO[]> => {
        return await api.get<SalaryGradeDTO[]>(`${BASE_URL}/categories/${categoryId}/grades`);
    },
    createGrade: async (data: any): Promise<SalaryGradeDTO> => {
        return await api.post<SalaryGradeDTO>(`${BASE_URL}/grades`, data);
    },
    updateGrade: async (id: string, data: any): Promise<SalaryGradeDTO> => {
        return await api.put<SalaryGradeDTO>(`${BASE_URL}/grades/${id}`, data);
    },
    deleteGrade: async (id: string): Promise<void> => {
        await api.delete(`${BASE_URL}/grades/${id}`);
    },

    // Steps
    getStepsByGrade: async (gradeId: string): Promise<SalaryStepDTO[]> => {
        return await api.get<SalaryStepDTO[]>(`${BASE_URL}/grades/${gradeId}/steps`);
    },
    createStep: async (data: any): Promise<SalaryStepDTO> => {
        return await api.post<SalaryStepDTO>(`${BASE_URL}/steps`, data);
    },
    deleteStep: async (id: string): Promise<void> => {
        await api.delete(`${BASE_URL}/steps/${id}`);
    },

    // Grid
    getGridByStep: async (stepId: string): Promise<SalaryGridDTO[]> => {
        return await api.get<SalaryGridDTO[]>(`${BASE_URL}/steps/${stepId}/grid`);
    },
    createGridEntry: async (data: any): Promise<SalaryGridDTO> => {
        return await api.post<SalaryGridDTO>(`${BASE_URL}/grid`, data);
    },

    getSummary: async (): Promise<SalaryStructureFullDTO> => {
        return await api.get<SalaryStructureFullDTO>(`${BASE_URL}/summary`);
    }
};
