/**
 *
 * @description Alert system state handler
 * * source : https://redux-toolkit.js.org/api/createslice
 */


import { createSlice , PayloadAction } from '@reduxjs/toolkit'

type IinitialState = {
    value: AlertState;
}

type AlertState = {
   success: boolean | null;
   message: string,
}

const initialState = {
    value: {
        success: null,
        message: '',
    }
} as IinitialState

export const alert = createSlice({
    name: "alert",
    initialState,
    reducers: {
        clearAlert: () => {
            return initialState
        },
        fireAlert: (state , action: PayloadAction<AlertState>) => {
            return {
                value: {
                    success: action.payload.success,
                    message: action.payload.message,
                }
            }
        }
    }
})

export const { clearAlert , fireAlert } = alert.actions;
export default alert.reducer;