/**
 * File: blogSlice.ts
 * Description:
 * - This file defines the Redux slice for managing blog-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 blog scenarios such as blog list, etc.
*/
import { BlogListResponse, BlogState } from '@/redux/types/blogTypes';
import { createSlice, PayloadAction } from '@reduxjs/toolkit';

const initialState: BlogState = {
    blogList: null,
    isLoading: false,
    blogBannerList: null,
}

const blogSlice = createSlice({
    name: 'blog',
    initialState,
    reducers: {
        /**
         * Used to start the request of blog list api call
         * @param state: State is the object data of credential passed
         */
        requestBlogList: (state) => {
            state.isLoading = true;
        },
        /**
         * Used to get the actual success response of the blog list api
         * @param state: State is the object data of credential passed
         */
        successBlogList: (state, action: PayloadAction<BlogListResponse>) => {
            state.blogList = action.payload;
            state.isLoading = false;
        },
        /**
         * Used to get the error response of the blog list api
         * @param state: State is the object data of credential passed
         */
        failureBlogList: (state) => {
            state.isLoading = false;
            state.blogList = null;
            state.blogBannerList = null;
        },

        /**
         * Used to get the actual success response of the blog banner list api
         * @param state: State is the object data of credential passed
         */
        responseBlogBannerList: (state, action: PayloadAction<BlogListResponse>) => {
            state.blogBannerList = action.payload;
            state.isLoading = false;
        },
    },
})

export const blogActions = blogSlice.actions
export default blogSlice.reducer;







