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



export const rubix = createApi({
  reducerPath: "rubix", 
  baseQuery: fetchBaseQuery({
    baseUrl: import.meta.env.VITE_BASE_URL,
  }),
  tagTypes: [
    "getTransCount",
    "getTransAll",
    "getTransById",
    "getMainNet",
    "getAllMainNetCount"
  ],
  endpoints: (builder) => ({




    getKPIDetails: builder.query({
      query: () => `Analytics/GetKPIDetails`,
      providesTags: ["getKPIDetails"],
    }),

    getTransCount: builder.query({
      query: () => `Analytics/Transactions/GetCount`,
      providesTags: ["getTransCount"],
    }),


    getTransAll: builder.query({
      query: ({ pageNumber = 1, pageSize = 10 }) => `Analytics/Transactions/GetAll?pageNumber=${pageNumber}&pageSize=${pageSize}`,
      providesTags: ["getTransAll"],
    }),
    
    
    getTransById: builder.query({
      query: (id) => `Transaction/GetById/${id}`,
      providesTags: ["getTransById"],
    }),
    
    
    getMainNetCount: builder.query({
      query: () => `MainNet/Transactions/GetCount`,
      providesTags: ["getAllMainNetCount"],
    }),
    
    getMainNet: builder.query({
      query: ({ pageNumber = 1, pageSize = 10 }) => `MainNet/Transactions/GetAll?pageNumber=${pageNumber}&pageSize=${pageSize}`,
      providesTags: ["getMainNet"],
    }),
    
    getDidById: builder.query({
      query: (id) => `DIDInfo/GetById/${id}`,
      providesTags: ["getTransById"],
    }),
    
    getMonthlyData: builder.query({
      query: (timeZoneId) => `/Analytics/monthly-summary`,
      providesTags: ["getMonthlyData"],
    }),
    
    getDailyData: builder.query({
      query: (timeZoneId) => `/Analytics/daily-summary?timeZoneId=${timeZoneId}`,
      providesTags: ["getDailyData"],
    }),
    
    getDateWiseData: builder.query({
      query: (timeZoneId) => `/Analytics/datewise-summary`,
      providesTags: ["getDateWiseData"],
    }),
    
    getSubnetCount: builder.query({
      query: () => `/SubNet/Transactions/GetCount`,
      providesTags: ["getSubnetCount"],
    }),


    // getSubnetAll: builder.query({
    //   query: ({ pageNumber = 1, pageSize = 10 }) => `Analytics/Transactions/GetAll?pageNumber=${pageNumber}&pageSize=${pageSize}`,
    //   providesTags: ["getTransAll"],
    // }),

    getSubnetById: builder.query({
      query: ({id,pageNumber = 1, pageSize = 10  }) => `SubNet/Transactions/GetAll/${id}?pageNumber=${pageNumber}&pageSize=${pageSize}`,
      providesTags: ["getTransById"],
    }),


    getSubnetAll: builder.query({
      query: ({ pageNumber = 1, pageSize = 10, searchTerm }) => `SubNet/GetAllSubnetworks?pageNumber=${pageNumber}&pageSize=${pageSize}&searchFilter=${searchTerm || ""}`,
      providesTags: ["getSubnetTransAll"],
    }),

    // getSubnetAll: builder.query({
    //   query: ({ pageNumber = 1, pageSize = 10 }) => `SubNet/GetAllSubnetworks?pageNumber=${pageNumber}&pageSize=${pageSize}?subnetId=${searchTerm || ""}`,
    //   providesTags: ["getTransAll"],
    // }),


    gnerateShortUrl: builder.mutation({
      query: (data) => ({
        url: `ShortUrl/create`,
        method: "POST",
        body: data,
      }),
      
    }),
    
  }),
});
export const {
  useGetKPIDetailsQuery,
  useGetTransCountQuery,
  useGetTransAllQuery,
  useGetTransByIdQuery,
  useGetMainNetCountQuery,
  useGetMainNetQuery,
  useGetDidByIdQuery,
  useGetMonthlyDataQuery,
  useGetDailyDataQuery,
  useGetDateWiseDataQuery,
  useGetSubnetCountQuery,
  useGetSubnetByIdQuery,
  useGetSubnetAllQuery,
  useGnerateShortUrlMutation
} = rubix;
