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

// src/hooks/api/api-keys.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var API_KEYS_QUERY_KEY = "api_keys";
var apiKeysQueryKeys = queryKeysFactory(API_KEYS_QUERY_KEY);
var useApiKey = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.apiKeys.$id.query({ $id: id, ...query }),
    queryKey: apiKeysQueryKeys.detail(id),
    ...options
  });
  return { ...data, ...rest };
};
var useApiKeys = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.apiKeys.query({ ...query }),
    queryKey: apiKeysQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateApiKey = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.apiKeys.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateApiKey = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.apiKeys.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useRevokeApiKey = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.apiKeys.$id.revoke.mutate({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteApiKey = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.apiKeys.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useBatchRemoveSalesChannelsFromApiKey = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.apiKeys.$id.salesChannels.mutate({ $id: id, remove: payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) });
      queryClient.invalidateQueries({
        queryKey: salesChannelsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useBatchAddSalesChannelsToApiKey = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.apiKeys.$id.salesChannels.mutate({ $id: id, add: payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: apiKeysQueryKeys.detail(id) });
      queryClient.invalidateQueries({
        queryKey: salesChannelsQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  apiKeysQueryKeys,
  useApiKey,
  useApiKeys,
  useCreateApiKey,
  useUpdateApiKey,
  useRevokeApiKey,
  useDeleteApiKey,
  useBatchRemoveSalesChannelsFromApiKey,
  useBatchAddSalesChannelsToApiKey
};
