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

// src/hooks/api/attributes.ts
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var ATTRIBUTES_QUERY_KEY = "attributes";
var attributesQueryKeys = queryKeysFactory(ATTRIBUTES_QUERY_KEY);
var useAttribute = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryKey: attributesQueryKeys.detail(id, query),
    queryFn: async () => sdk.admin.attributes.$id.query({ $id: id, ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useAttributes = (query, options) => {
  const { data, ...rest } = useQuery({
    queryKey: attributesQueryKeys.list(query),
    queryFn: async () => sdk.admin.attributes.query({ ...query }),
    ...options
  });
  return { ...data, ...rest };
};
var useCreateAttribute = (options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.attributes.mutate(payload),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: attributesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateAttribute = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.attributes.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: attributesQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: attributesQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteAttribute = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.attributes.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: attributesQueryKeys.lists()
      });
      queryClient.invalidateQueries({
        queryKey: attributesQueryKeys.detail(id)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useCreateAttributePossibleValue = (attributeId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.attributes.$id.values.mutate({
      $id: attributeId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: attributesQueryKeys.detail(attributeId)
      });
      queryClient.invalidateQueries({
        queryKey: attributesQueryKeys.lists()
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useUpdateAttributePossibleValue = (attributeId, valueId, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.attributes.$id.values.$valueId.mutate({
      $id: attributeId,
      $valueId: valueId,
      ...payload
    }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({
        queryKey: attributesQueryKeys.detail(attributeId)
      });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  attributesQueryKeys,
  useAttribute,
  useAttributes,
  useCreateAttribute,
  useUpdateAttribute,
  useDeleteAttribute,
  useCreateAttributePossibleValue,
  useUpdateAttributePossibleValue
};
