import {
  pricePreferencesQueryKeys
} from "./chunk-7SJC6BWZ.js";
import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  queryKeysFactory
} from "./chunk-ZA2KFUFR.js";
import {
  sdk
} from "./chunk-RIN4CBRB.js";

// src/hooks/api/regions.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var REGIONS_QUERY_KEY = "regions";
var regionsQueryKeys = queryKeysFactory(REGIONS_QUERY_KEY);
var useRegion = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryKey: regionsQueryKeys.detail(id, query),
    queryFn: () => sdk.admin.regions.$id.query({ $id: id, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useRegions = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.regions.query({ ...query }),
    queryKey: regionsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateRegion = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.regions.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: regionsQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: pricePreferencesQueryKeys.list()
      });
      queryClient.invalidateQueries({
        queryKey: pricePreferencesQueryKeys.details()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateRegion = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.regions.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: regionsQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: regionsQueryKeys.details() });
      queryClient.invalidateQueries({
        queryKey: pricePreferencesQueryKeys.list()
      });
      queryClient.invalidateQueries({
        queryKey: pricePreferencesQueryKeys.details()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteRegion = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.regions.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: regionsQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: regionsQueryKeys.detail(id) });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  regionsQueryKeys,
  useRegion,
  useRegions,
  useCreateRegion,
  useUpdateRegion,
  useDeleteRegion
};
