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

const initialState = {
    message:{},
    arcLoading: true,
    arcError: null
}

const deleteOrdersSlice = createSlice({
    name: "deleteOrders",
    initialState,
    reducers:{
        arcLoadingTrue: (state) => {
            state.arcLoading = true
        },
        resetOrder: (state) => {
            state.message = {}
            state.arcLoading = true
            state.arcError = null
        }
    },
    extraReducers:(builder)=>{
        // Get Orders
        builder.addCase(archiveOrdersDelete.pending, (state) => {
            state.arcLoading = true;
            state.arcError = null;
        })
        builder.addCase(archiveOrdersDelete.fulfilled, (state, action) => {
            state.arcLoading = false;
            state.message = action.payload;
        })
        builder.addCase(archiveOrdersDelete.rejected, (state, action) => {
            state.arcLoading = false;
            state.arcError = action.payload;
        });
    }
})

export const { arcLoadingTrue, resetOrder } = deleteOrdersSlice.actions;
export default deleteOrdersSlice.reducer;