import { api } from '@/services/api';



export interface ChoiceDataResponse {
    id?: string,
    choice?: string,
    status?: true,
    questionId?: string
}
export interface ChoiceDataResponseByID {
    success: boolean,
    message: string
    info: ChoiceDataResponse
}


export interface ChoiceGetDataResponse {

    success: boolean,
    message: string
    details: {
        docs: ChoiceDataResponse[],
        pages: number
        total: number
    }
}

export const Choice = api.injectEndpoints({
    endpoints: (build) => ({
        ChoiceGetData: build.query<ChoiceGetDataResponse, { search?: string, page: number, paginate: number }>({
            query: (params) => ({
                url: `/choice/showall`,
                method: 'GET',
                params
            }),
            providesTags: ['ChoiceGetData'],
        }),
        ChoiceGetDataById: build.query<ChoiceDataResponseByID, { id: string }>({
            query: (params) => ({
                url: `/choice`,
                params
            }),
            providesTags: ['ChoiceGetDataById'],
        }),
        ChoiceCreate: build.mutation<ChoiceDataResponse, ChoiceDataResponse>({
            query: (body) => ({
                url: '/choice',
                method: 'POST',
                body,
            }),
            invalidatesTags: ['ChoiceGetData', 'ChoiceCreate', "ChoiceGetDataById"],
        }),
        ChoiceUpdate: build.mutation<ChoiceDataResponse, ChoiceDataResponse>({
            query: (body) => ({
                url: '/choice',
                body,
                method: 'PUT',
            }),
            invalidatesTags: ['ChoiceGetData', "ChoiceGetDataById", 'ChoiceCreate', 'ChoiceUpdate'],
        }),

        ChoiceRemove: build.mutation<void, { id: string }>({
            query: (params) => ({
                url: `/choice`,
                method: 'DELETE',
                params
            }),
            invalidatesTags: ['ChoiceGetData', "ChoiceGetDataById", 'ChoiceRemove'],
        }),
    }),
});

export const {
    useChoiceGetDataQuery,
    useLazyChoiceGetDataQuery,
    useChoiceCreateMutation,
    useChoiceGetDataByIdQuery,
    useLazyChoiceGetDataByIdQuery,
    useChoiceUpdateMutation,
    useChoiceRemoveMutation,

} = Choice;