import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  queryKeysFactory
} from "./chunk-ZA2KFUFR.js";
import {
  sdk
} from "./chunk-DTGEFKK4.js";

// src/hooks/api/customers.tsx
import {
  useMutation as useMutation2,
  useQuery as useQuery2
} from "@tanstack/react-query";

// src/hooks/api/customer-groups.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var CUSTOMER_GROUPS_QUERY_KEY = "customer_groups";
var customerGroupsQueryKeys = queryKeysFactory(
  CUSTOMER_GROUPS_QUERY_KEY
);
var useCustomerGroup = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryKey: customerGroupsQueryKeys.detail(id, query),
    queryFn: async () => sdk.vendor.customerGroups.$id.query({ $id: id, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useCustomerGroups = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.vendor.customerGroups.query({ ...query }),
    queryKey: customerGroupsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateCustomerGroup = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.customerGroups.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateCustomerGroup = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.customerGroups.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteCustomerGroup = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.vendor.customerGroups.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteCustomerGroupLazy = (options) => {
  return useMutation({
    mutationFn: ({ id }) => sdk.vendor.customerGroups.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.detail(variables.id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useAddCustomersToGroup = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.customerGroups.$id.customers.mutate({ $id: id, add: payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: customersQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRemoveCustomersFromGroup = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.vendor.customerGroups.$id.customers.mutate({ $id: id, remove: payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: customersQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

// src/hooks/api/customers.tsx
var CUSTOMERS_QUERY_KEY = "customers";
var customersQueryKeys = queryKeysFactory(CUSTOMERS_QUERY_KEY);
var customerAddressesQueryKeys = queryKeysFactory(
  `${CUSTOMERS_QUERY_KEY}-addresses`
);
var useCustomer = (id, query, options) => {
  const { data, ...rest } = useQuery2({
    queryKey: customersQueryKeys.detail(id, query),
    queryFn: async () => sdk.vendor.customers.$id.query({ $id: id, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useCustomers = (query, options) => {
  const { data, ...rest } = useQuery2({
    queryFn: () => sdk.vendor.customers.query({ ...query }),
    queryKey: customersQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useBatchCustomerCustomerGroups = (id, options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.vendor.customers.$id.customerGroups.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.details()
      });
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: customersQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: customersQueryKeys.details()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  customersQueryKeys,
  useCustomer,
  useCustomers,
  useBatchCustomerCustomerGroups,
  customerGroupsQueryKeys,
  useCustomerGroup,
  useCustomerGroups,
  useCreateCustomerGroup,
  useUpdateCustomerGroup,
  useDeleteCustomerGroup,
  useDeleteCustomerGroupLazy,
  useAddCustomersToGroup,
  useRemoveCustomersFromGroup
};
