import { baseApi } from "./baseApi";
import { API_ENDPOINTS } from "./constant";
import { ICategory, ICategoryListItem } from "./types/common";

export const categoryApi = baseApi.injectEndpoints({
  endpoints: (builder) => ({
    getCategoryTree: builder.query<ICategory[], string>({
      query: (categoryTypeCode) => ({
        url: `${API_ENDPOINTS.categoryTree}/${categoryTypeCode}/tree`,
        method: "GET",
      }),
    }),
    getCategoryList: builder.query<ICategoryListItem[], string>({
      query: (categoryTypeCode) => ({
        url: `${API_ENDPOINTS.categoryTree}/${categoryTypeCode}/listAll?sortBy=id&sortDirection=desc`,
        method: "GET",
      }),
    }),
  }),
});

export const {
  useGetCategoryTreeQuery,
  useLazyGetCategoryTreeQuery,
  useGetCategoryListQuery,
} = categoryApi;
