import { createApi } from "@reduxjs/toolkit/query/react";
import { baseQueryWithReauth } from "./apiSlice";

export type TotalUser = {
    data: {
        totalRecruiterCount: number;
        totalCustomerCount: string;
        totalUserCount: string;
        recruitersByMonth: Record<string, number>;
        customersByMonth: Record<string, number>;
    };
};

export type PastUser = {
    data: {
        past24hourRecruiterCount: number;
        past24hourCustomercount: number;
    };
};

export type NewUser = {
    data: {
        newRecuiterCount: number;
        newCustomerCount: number;
        newTotalUserCount: number;
    };
};

export type AgencyList = {
    data: [
        {
            id: number;
            name: string;
            created_at: string;
            is_active: boolean
        }
    ];
};

export type FaqList = {
    data: [
        {
            id: number;
            faqs_xid: number;
            language_master_xid: number;
            question: string;
            answer: string;
            is_active: boolean
        }
    ];
};


export const dashBoard = createApi({
    reducerPath: "dashBoard",
    baseQuery: baseQueryWithReauth, // Use enhanced baseQuery with error handling
    endpoints: (builder) => ({

        getTotalUser: builder.query<TotalUser, void>({ query: () => "/dashboard-total-user" }),
        getPastUser: builder.query<PastUser, void>({ query: () => "/dashboard-past-user" }),
        getNewUser: builder.query<NewUser, void>({ query: () => "/dashboard-new-user" }),
        getAgencyList: builder.query<AgencyList, void>({ query: () => "/dashboard-agency-list" }),
        getFaqList: builder.query<FaqList, void>({ query: () => "/dashboard-faq-list" }),




    }),
});

export const {
    useGetTotalUserQuery,
    useGetPastUserQuery,
    useGetNewUserQuery,
    useGetAgencyListQuery,
    useGetFaqListQuery,
} = dashBoard;
