import {
  queryClient
} from "./chunk-RHKRREUU.js";
import {
  queryKeysFactory
} from "./chunk-ZA2KFUFR.js";
import {
  sdk
} from "./chunk-RIN4CBRB.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({
    queryFn: () => sdk.admin.customerGroups.$id.query({ $id: id, ...query }),
    queryKey: customerGroupsQueryKeys.detail(id),
    ...options
  });
  return { ...data, ...rest };
};
var useCustomerGroups = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.customerGroups.query({ ...query }),
    queryKey: customerGroupsQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateCustomerGroup = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.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.admin.customerGroups.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteCustomerGroup = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.customerGroups.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.detail(id)
      });
      queryClient.invalidateQueries({
        queryKey: customerGroupsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRemoveCustomersFromGroup = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.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
  });
};
var useDeleteCustomerGroupLazy = (options) => {
  return useMutation({
    mutationFn: ({ id }) => sdk.admin.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.admin.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
  });
};

// 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),
    queryFn: () => sdk.admin.customers.$id.query({ $id: id, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useCustomers = (query, options) => {
  const { data, ...rest } = useQuery2({
    queryFn: () => sdk.admin.customers.query({ ...query }),
    queryKey: customersQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateCustomer = (options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.admin.customers.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateCustomer = (id, options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.admin.customers.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: customersQueryKeys.detail(id) });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteCustomer = (id, options) => {
  return useMutation2({
    mutationFn: () => sdk.admin.customers.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() });
      queryClient.invalidateQueries({
        queryKey: customersQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useBatchCustomerCustomerGroups = (id, options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.admin.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
  });
};
var useCreateCustomerAddress = (id, options) => {
  return useMutation2({
    mutationFn: (payload) => sdk.admin.customers.$id.addresses.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: customersQueryKeys.detail(id) });
      queryClient.invalidateQueries({
        queryKey: customerAddressesQueryKeys.list(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteCustomerAddress = (id, options) => {
  return useMutation2({
    mutationFn: (addressId) => sdk.admin.customers.$id.addresses.$addressId.delete({
      $id: id,
      $addressId: addressId
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: customersQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: customersQueryKeys.detail(id) });
      queryClient.invalidateQueries({
        queryKey: customerAddressesQueryKeys.list(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  useCustomer,
  useCustomers,
  useCreateCustomer,
  useUpdateCustomer,
  useDeleteCustomer,
  useBatchCustomerCustomerGroups,
  useCreateCustomerAddress,
  useDeleteCustomerAddress,
  customerGroupsQueryKeys,
  useCustomerGroup,
  useCustomerGroups,
  useCreateCustomerGroup,
  useUpdateCustomerGroup,
  useDeleteCustomerGroup,
  useRemoveCustomersFromGroup,
  useDeleteCustomerGroupLazy,
  useAddCustomersToGroup
};
