/**
 * File: contactUsSlice.ts
 * Description:
 * - This file defines the Redux slice for managing contact us-related state in the application.
 * - It uses Redux Toolkit's `createSlice` to simplify state management and reduce boilerplate code.
 * - The slice contains actions and reducers for handling various contact us scenarios such as contact us, etc.
*/


import { ContactUsState } from '@/redux/types/contactUsType';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';


const initialState: ContactUsState = {
    isLoading: false,
    data: null,
}


const contactUsSlice = createSlice({
    name: 'contactUs',
    initialState,
    reducers: {
        /**
         * Used to start the request of contact us api call
         * @param state: State is initial state of contact us
         */
        RequestContactUs: (state) => {
            state.isLoading = true;
        },
        /**
         * Used to set the contact us data
         * @param state: State is initial state of contact us
         * @param action: Action is data of contact us success response
         */
        SuccessContactUs: (state, action: PayloadAction<any>) => {
            state.data = action.payload;
            state.isLoading = false;
        },
        /**
         * Used to set the error of contact us api call
         * @param state: State is initial state of contact us
         */
        ErrorContactUs: (state) => {
            state.isLoading = false;
            state.data = null;
        },
    },
});

export const contactUsActions = contactUsSlice.actions
export default contactUsSlice.reducer;
