import { createSlice, createAsyncThunk } from "@reduxjs/toolkit";
import { GET } from "../../utils/api";
import { API } from "../../endpoints/common_endpoints";


// Thunk for getting Add banners
export const getFaq = createAsyncThunk(
    'masters/add-faq',
    async (_, { rejectWithValue }) => {
        try {
            const faqData = await GET(API.GET_FAQ);

          
            
            return faqData;

        } catch (error) {
            return rejectWithValue(error.message);
        }
    }
);
export const getSubfaq = createAsyncThunk(
    'masters/add-subfaq',
    async (id, { rejectWithValue }) => {
        try {
            const subfaqData = await GET(API.GET_SUBFAQ + `/${id}`);
            return subfaqData;

        } catch (error) {
            return rejectWithValue(error.message);
        }
    }
);

// Create the slice
const Slice = createSlice({
    name: "faq",
    initialState: {
       getfaq:[],    
        error: null,
        status: 'idle',
    },
    reducers: {},
    extraReducers: (builder) => {
        builder

            .addCase(getFaq.pending, (state) => {
                state.status = 'loading';
                
            })
            .addCase(getFaq.fulfilled, (state, action) => {
                state.status = 'succeeded';
                state.getfaq = action.payload?.data || [];
              
            })
            .addCase(getFaq.rejected, (state, action) => {
                state.status = 'failed';
                state.error = action.payload;
               
            })

    },
});

export default Slice.reducer;


