// investorDetails.service.js
import { createApi, fetchBaseQuery } from "@reduxjs/toolkit/query/react";
// import { api } from "./api.service";
import { baseQuery } from "./token.serivce";

// const baseUrl = api?.defaults.baseURL;

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

    getDrawalRequest: builder.query({
      query: () => `/withdrawal/admin`,
      providesTags: ["getDrawalRequest"],
    }),

    getDrawalRequestById: builder.query({
      query: (id) => `/withdrawal/admin/getById/${id}`,
    }),

    updateDrawalRequest: builder.mutation({
      query: ({ id, data }) => ({
        url: `/withdrawal/admin/updateApprove/${id}`,
        method: "PATCH",
        body: data,
      }),
      invalidatesTags: ["getDrawalRequest", "getDepositHistory"],
    }),

    depositReject: builder.mutation({
      query: ({ id, data }) => ({
        url: `/deposit/admin/rejected/${id}`,
        method: "PATCH",
        body: data,
      }),
      invalidatesTags: ["getDepositRequest", "getDepositHistory"],
    }),

    getDrawalHistory: builder.query({
      query: () => `/withdrawal/admin/history`,
      providesTags: ["getDepositHistory"],
    }),
  }),
});

// Export hooks for usage in functional components
export const {
  useGetDrawalRequestQuery,
  useUpdateDrawalRequestMutation,
  useGetDrawalRequestByIdQuery,
  useDepositRejectMutation,
  useGetDrawalHistoryQuery
} = drawalRequest;
