import apiClient from '../common/axios-instance.js';

const scheduleService = {

    getAllJobs: async (searchParams) => {
        const response = await apiClient.get('/api/schedule', { params: searchParams });
        return response.data.data;
    },
    
    getJobDetail: async (groupName, jobName) => {
        const response = await apiClient.get(`/api/schedule/${groupName}/${jobName}`);
        return response.data.data;
    },
    
    pauseJob: async (groupName, jobName) => {
        await apiClient.get(`/api/schedule/pause/${groupName}/${jobName}`);
        return true;
    },
    
    resumeJob: async (groupName, jobName) => {
        await apiClient.get(`/api/schedule/resume/${groupName}/${jobName}`);
        return true;
    },
    
    triggerJob: async (groupName, jobName) => {
        await apiClient.get(`/api/schedule/trigger/${groupName}/${jobName}`);
        return true;
    },
    
    rescheduleJob: async (jobGroup, jobName, cronExpression) => {
        const response = await apiClient.post('/api/schedule/reschedule', {
            jobGroup,
            jobName,
            cronExpression
        });
        return response.data.data;
    },

    refreshJob: async () => {
        await apiClient.post('/actuator/refresh');
        return true;
    }

};

export default scheduleService;

