import {createSlice} from "@reduxjs/toolkit";
import {startBgProcess} from "../httpServices/httpServiceArchive";

const initialState = {
    bgProcessing: [],
    processLoading: true,
    processError: null
}

const bgProcessSlice = createSlice({
    name: 'backgroundProcess',
    initialState,
    reducers:{
        setProcessLoadingTrue: (state) => {
            state.processLoading = true
        },
    },
    extraReducers:(builder)=>{
        // Get Orders
        builder.addCase(startBgProcess.pending, (state) => {
            state.processLoading = true;
            state.processError = null;
        })
        builder.addCase(startBgProcess.fulfilled, (state, action) => {
            state.processLoading = false;
            state.bgProcessing = action.payload;
        })
        builder.addCase(startBgProcess.rejected, (state, action) => {
            state.processLoading = false;
            state.processError = action.payload;
        });
    }
})

export const { setProcessLoadingTrue } = bgProcessSlice.actions;
export default bgProcessSlice.reducer;