import { api } from './api';
import { CreateQuestionRequest } from './questions';

type GetChoiceByIdResponse = {
    success: boolean,
    message: string,
    info: CreateChoiceRequest
}
type GetChoicesResponse = {
    success: boolean,
    message: string,
    details: {
        docs: CreateChoiceRequest[],
        pages: 1,
        total: 1
    }
}

export interface CreateChoiceRequest  {
    id?: string,
    choice?: string,
    status?: boolean,
    questionId: string, 
    Question?:CreateQuestionRequest
}
export type CreateChoiceResponse = {
    success: boolean,
    message: string,
    result: CreateChoiceRequest
}
export const Choice = api.injectEndpoints({
    endpoints: (build) => ({
        CreateChoice: build.mutation<CreateChoiceResponse, CreateChoiceRequest>({
            query: (body) => ({
                url: 'choice',
                method: 'POST',
                body,
            }),
            invalidatesTags: ['CreateChoice'],
        }),
        getChoices: build.query<GetChoicesResponse, any>({
            query: (params) => ({
                url: `choices/showall`,
                method: 'GET',
                // params,
            }),
            providesTags: ['getChoice', "CreateChoice"],
        }),
        getChoiceById: build.query<GetChoiceByIdResponse, { id: string }>({
            query: (params) => ({
                url: `choice`,
                method: 'GET',
                params,
            }),
            providesTags: ['getChoiceById', "CreateChoice"],
        }),

    }),
});

export const {
    useCreateChoiceMutation,
    useGetChoicesQuery,
    useGetChoiceByIdQuery
} = Choice;