import { baseApi } from "./baseApi";
import { API_ENDPOINTS } from "./constant";
import { IPlanListParams, IPlanListResponse } from "./types/plan";

export const planApi = baseApi.injectEndpoints({
  endpoints: (builder) => ({
    getPlanList: builder.query<IPlanListResponse, IPlanListParams | void>({
      query: (params) => ({
        url: API_ENDPOINTS.planList,
        method: "GET",
        params: params ?? undefined,
      }),
      // Plan prices are returned per the user's billing region, so this must be
      // refetched whenever the region changes (updateBillingRegion invalidates
      // the `Plan` tag).
      providesTags: ["Plan"],
    }),
  }),
});

export const { useGetPlanListQuery } = planApi;
