import { api } from './api';

export type RegisterResponse = {
    success: boolean,
    message: string,
    result: {
        id: string,
        fullName: string,
        role: string,
        password: string,
        email: string
        photo: string
        username: string
    }
}

type GetUserByIdResponse =
    {
        success: boolean,
        message: string,
        info: {
            id: string,
            fullName: string,
            role: string,
            password: string,
            country: string,
            mobile: string,
            email: string,
            status: boolean,
            photo: string,
            username: string
        }
    }


export interface getUsersResponse {
    success: true,
    message: string
    details: {
        docs: [
            {
                id: string
                fullName: null | string,
                role: "admin" | "user",
                username: string,
                password: string,
                country: null | string,
                mobile: null | string,
                email: null | string,
                status: null | string,
                photo: null | string,
                clinet_token: null | string,
                hashRt: string
            }
        ],
        pages: number
        total: number
    }
}



export const User = api.injectEndpoints({
    endpoints: (build) => ({
        register: build.mutation<RegisterResponse, FormData>({
            query: (body: FormData) => ({
                url: 'user/register',
                method: 'POST',
                body,
            }),
            invalidatesTags: ['register',],
        }),
        getUsers: build.query<getUsersResponse, any>({
            query: (params) => ({
                url: `/user/showall`,
                method: 'GET',
                params,
            }),
            // providesTags: ['getUsers'],
        }),

        getUserById: build.query<GetUserByIdResponse, string>({
            query: (id: string) => ({
                url: `/user?id=${id}`,
                method: 'GET',
            }),
            // providesTags: ['getUserById'], 
        }),
        // getAdminById: build.query<GetAdminByIdResponse, string>({
        //     query: (id: string) => ({
        //         url: `/user/admin/${id}`,
        //         method: 'GET',
        //     }),
        //     providesTags: ['getAdminById'],
        // }),

        // addUser: build.mutation<any, FormData>({
        //     query: (body: FormData) => ({
        //         url: '/auth/local/signup',
        //         method: 'POST',
        //         body,
        //     }),
        //     invalidatesTags: ['getUsers', 'addUser'],
        // }),
        // updateUser: build.mutation<any, { id: string; body: FormData; fileNames: string }>({
        //     query: ({ id, body }: { id: string; body: FormData; fileNames: string }) => ({
        //         url: `/user/${id}`,
        //         body,
        //         method: 'PATCH',
        //     }),
        //     invalidatesTags: ['getUsers', 'updateUser', 'getUserById'],
        // }),
        // deleteUser: build.mutation<any, { id: string }>({
        //     query: (params: { id: string }) => ({
        //         url: `/user/${params.id}`,
        //         method: 'DELETE',
        //     }),
        //     invalidatesTags: ['getUsers', 'deleteUser'],
        // }),



    }),
});

export const {
    useRegisterMutation,
    useGetUsersQuery,
    useGetUserByIdQuery,
    useLazyGetUserByIdQuery
} = User;