import { useQuery } from "@tanstack/react-query";
import {
  getOrganizationTypes,
  OrgTypeResponse,
} from "@/record-management/services/api/organizationTypesService";
import Cookies from "js-cookie";

export const useOrganizationTypes = () => {
  const {
    data: organizationTypesResponse,
    isLoading,
    isError,
    refetch,
  } = useQuery<OrgTypeResponse>({
    queryKey: ["organizationTypes"],
    queryFn: async () => {
      const response = await getOrganizationTypes();
      return response.data;
    },
    staleTime: 5 * 60 * 1000,
    enabled: !!Cookies.get("tenant-key"), // Only run when tenantKey is present
  });

  return {
    organizationTypesResponse,
    isLoading,
    isError,
    refetch,
  };
};
