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



export interface PracVideoDataResponse {
    id: string
    title: string,
    videoUrl: string,
    description: string,
    status: boolean,
    pracListId: string
    PreviewVideos: any[]
}
export interface PracVideoDataResponseByID {
    success: boolean,
    message: string
    info: PracVideoDataResponse
}


export interface PracVideoGetDataResponse {

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

export interface PracVideoCreate {
    id?: string
    title: string,
    videoUrl: string,
    description: string,
    status: boolean,
    pracListId: string
}

export const PracVideo = api.injectEndpoints({
    endpoints: (build) => ({
        PracVideoGetData: build.query<PracVideoGetDataResponse, { search?: string, page: number, paginate: number }>({
            query: (params) => ({
                url: `/pracVideos/showall`,
                method: 'GET',
                params
            }),
            providesTags: ['PracVideoGetData'],
        }),
        PracVideoGetDataById: build.query<PracVideoDataResponseByID, { id: string }>({
            query: (params) => ({
                url: `/pracVideos`,
                params
            }),
            providesTags: ['PracVideoGetDataById'],
        }),
        PracVideoCreate: build.mutation<PracVideoDataResponse, PracVideoCreate>({
            query: (body) => ({
                url: '/pracVideos',
                method: 'POST',
                body,
            }),
            invalidatesTags: ['PracVideoGetData', 'PracVideoCreate', "PracVideoGetDataById"],
        }),
        PracVideoUpdate: build.mutation<PracVideoDataResponse, PracVideoCreate>({
            query: (body) => ({
                url: '/pracVideos',
                body,
                method: 'PUT',

            }),
            invalidatesTags: ['PracVideoGetData', "PracVideoGetDataById", 'PracVideoCreate', 'PracVideoUpdate'],
        }),

        PracVideoRemove: build.mutation<void, { id: string }>({
            query: (params) => ({
                url: `/pracVideos`,
                method: 'DELETE',
                params
            }),
            invalidatesTags: ['PracVideoGetData', "PracVideoGetDataById", 'PracVideoRemove'],
        }),
    }),
});

export const {
    usePracVideoGetDataQuery,
    useLazyPracVideoGetDataQuery,
    usePracVideoCreateMutation,
    usePracVideoGetDataByIdQuery,
    useLazyPracVideoGetDataByIdQuery,
    usePracVideoUpdateMutation,
    usePracVideoRemoveMutation,
} = PracVideo;