import api from './api';

const BASE = '/onboarding-processes';

const onboardingProcessService = {
    // Departments
    getDepartments: async () => {
        const res = await api.get(`${BASE}/departments`);
        return res.data.data;
    },
    createDepartment: async (data) => {
        const res = await api.post(`${BASE}/departments`, data);
        return res.data.data;
    },
    updateDepartment: async (id, data) => {
        const res = await api.put(`${BASE}/departments/${id}`, data);
        return res.data.data;
    },
    deleteDepartment: async (id) => {
        await api.delete(`${BASE}/departments/${id}`);
    },
    reorderDepartments: async (ids) => {
        await api.put(`${BASE}/departments/reorder`, { ids });
    },

    // Processes
    getProcesses: async (params = {}) => {
        const res = await api.get(`${BASE}/processes`, { params });
        return res.data.data;
    },
    getChecklistProcesses: async (appliesTo, departmentId) => {
        // appliesTo: 'onboarding' or 'offboarding'; departmentId: optional filter
        const params = { applies_to: appliesTo };
        if (departmentId) params.department_id = departmentId;
        const res = await api.get(`${BASE}/processes`, { params });
        return res.data.data;
    },
    createProcess: async (data) => {
        const res = await api.post(`${BASE}/processes`, data);
        return res.data.data;
    },
    updateProcess: async (id, data) => {
        const res = await api.put(`${BASE}/processes/${id}`, data);
        return res.data.data;
    },
    deleteProcess: async (id) => {
        await api.delete(`${BASE}/processes/${id}`);
    },
    reorderProcesses: async (department_id, ids) => {
        await api.put(`${BASE}/processes/reorder`, { department_id, ids });
    },
};

export default onboardingProcessService;
