import { api } from '@/services/api';
import { PracVideoDataResponse } from './PracVideo';



export interface PracListDataResponse {

    id?: string
    title: string,
    playListUrl: string,
    description: string,
    status: boolean
    PracVideos: PracVideoDataResponse
}
export interface PracListDataResponseByID {
    success: boolean,
    message: string
    info: PracListDataResponse
}


export interface PracListGetDataResponse {

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

export interface PracListCreate {
    id?: string
    title: string,
    playListUrl: string,
    description: string,
    status: boolean
}

export const PracList = api.injectEndpoints({
    endpoints: (build) => ({
        PracListGetData: build.query<PracListGetDataResponse, { search?: string, page: number, paginate: number }>({
            query: (params) => ({
                url: `/pracLists/showall`,
                method: 'GET',
                params
            }),
            providesTags: ['PracListGetData'],
        }),
        PracListGetDataById: build.query<PracListDataResponseByID, { id: string }>({
            query: (params) => ({
                url: `/pracLists`,
                params
            }),
            providesTags: ['PracListGetDataById'],
        }),
        PracListCreate: build.mutation<PracListDataResponse, PracListCreate>({
            query: (body) => ({
                url: '/pracLists',
                method: 'POST',
                body,
            }),
            invalidatesTags: ['PracListGetData', 'PracListCreate', "PracListGetDataById"],
        }),
        PracListUpdate: build.mutation<PracListDataResponse, PracListCreate>({
            query: (body) => ({
                url: '/pracLists',
                body,
                method: 'PUT',

            }),
            invalidatesTags: ['PracListGetData', "PracListGetDataById", 'PracListCreate', 'PracListUpdate'],
        }),

        PracListRemove: build.mutation<void, { id: string }>({
            query: (params) => ({
                url: `/pracLists`,
                method: 'DELETE',
                params
            }),
            invalidatesTags: ['PracListGetData', "PracListGetDataById", 'PracListRemove'],
        }),
    }),
});

export const {
    usePracListGetDataQuery,
    useLazyPracListGetDataQuery,
    usePracListCreateMutation,
    usePracListGetDataByIdQuery,
    useLazyPracListGetDataByIdQuery,
    usePracListUpdateMutation,
    usePracListRemoveMutation,
} = PracList;