
// Need to use the React-specific entry point to import createApi
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
import { baseQuery } from "./token.serivce";



// Define a service using a base URL and expected endpoints
export const sabAdminMaster = createApi({
  reducerPath: "sabAdminMaster",
  baseQuery: baseQuery,
  tagTypes: ["getSubAdmin", "prePopulate"],
  endpoints: (builder) => ({



    // ======[Get All]=====

    getSubAdminMaster: builder.query({
      query: () => `/subadmin/admin/getAll`,
      providesTags: ["getSubAdmin"],
    }),

    // // ========[ Create ]========

    createSubAdmin: builder.mutation({
      query: (data) => ({
        url: `/subadmin/admin/create`,
        method: "POST",
        body: data,
      }),
      invalidatesTags: ["getSubAdmin","prePopulate"],
    }),

    // // ========[Update Sponser]========

    updateSubAdmin: builder.mutation({
      query: ({ data, id }) => ({
        url: `/subadmin/admin/${id}`,
        method: "PATCH",
        body: data,
      }),
      invalidatesTags: ["getSubAdmin"],
    }),

    getSubAdminById: builder.query({
      query: (id) => `/subadmin/admin/${id}`,
    }),

    // // ========[Toggle Status]========

    toggleStatus: builder.mutation({
      query: ({id, data}) => ({
        url: `/subadmin/admin/toggle-role/${id}`,
        method: "PATCH",
        body: data,
      }),
      invalidatesTags: ["getSubAdmin"],
    }),

    // // ========[Get Active]========

    // getActiveSponserMaster: builder.query({
    //   query: () => `/sponsor/admin/active`,
    // }),

    // getSponserMasterActive: builder.query({
    //   query: () => "/sponsor/admin/active",
    // }),

    // // ======[Get ID]=====

    // getSponserById: builder.query({
    //   query: (id) => `/sponsor/admin/${id}`,
    // }),

    // // ========[Update Sponser]========

    // updateSponser: builder.mutation({
    //   query: ({ data, id }) => ({
    //     url: `/sponsor/admin/${id}`,
    //     method: "PATCH",
    //     body: data,
    //   }),
    //   invalidatesTags: ["getSponser"],
    // }),

  }),
});

// Export hooks for usage in functional components
export const {
   useGetSubAdminMasterQuery,
   useCreateSubAdminMutation,
   useUpdateSubAdminMutation,
   useGetSubAdminByIdQuery,
   useToggleStatusMutation
} = sabAdminMaster;
