import {createSlice} from "@reduxjs/toolkit";
import {getSyncSchedule, insertSyncSchedule} from "../httpServices/httpServiceSyncSchedule";

const initialState = {
    syncSchedule:{},
    loading: true,
    error: null,
}

const syncScheduleSlice = createSlice({
    name: "syncSchedule",
    initialState,
    reducers:{},
    extraReducers:(builder)=>{
        // Add Schedule Settings
        builder.addCase(insertSyncSchedule.pending, (state, action) => {
            state.loading   = true;
            state.error     = null;
        });
        builder.addCase(insertSyncSchedule.fulfilled, (state, action) => {
            state.loading   = false;
            state.syncSchedule  = action.payload;
        });
        builder.addCase(insertSyncSchedule.rejected, (state,action) => {
            state.loading   = false;
            state.error     = action.payload;
        });

        // Get Schedule Settings
        builder.addCase(getSyncSchedule.pending, (state) => {
            state.loading   = true;
            state.error     = null;
        })
        builder.addCase(getSyncSchedule.fulfilled, (state, action) => {
            state.loading   = false;
            state.syncSchedule  = action.payload;
        })
        builder.addCase(getSyncSchedule.rejected, (state, action) => {
            state.loading   = false;
            state.error     = action.payload;
        });
    }
})

export default syncScheduleSlice.reducer;