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

// src/hooks/api/users.tsx
import {
  useMutation,
  useQuery
} from "@tanstack/react-query";
var USERS_QUERY_KEY = "users";
var usersQueryKeys = {
  ...queryKeysFactory(USERS_QUERY_KEY),
  me: () => [USERS_QUERY_KEY, "me"]
};
var useMe = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.users.me.query({ ...query }),
    queryKey: usersQueryKeys.me(),
    ...options
  });
  return {
    ...data,
    ...rest
  };
};
var useUser = (id, query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.users.$id.query({ $id: id, ...query }),
    queryKey: usersQueryKeys.detail(id),
    ...options
  });
  return { ...data, ...rest };
};
var useUsers = (query, options) => {
  const { data, ...rest } = useQuery({
    queryFn: () => sdk.admin.users.query({ ...query }),
    queryKey: usersQueryKeys.list(query),
    ...options
  });
  return { ...data, ...rest };
};
var useUpdateUser = (id, options) => {
  return useMutation({
    mutationFn: (payload) => sdk.admin.users.$id.mutate({ $id: id, ...payload }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: usersQueryKeys.detail(id) });
      queryClient.invalidateQueries({ queryKey: usersQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: usersQueryKeys.me() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};
var useDeleteUser = (id, options) => {
  return useMutation({
    mutationFn: () => sdk.admin.users.$id.delete({ $id: id }),
    onSuccess: (data, variables, context) => {
      queryClient.invalidateQueries({ queryKey: usersQueryKeys.detail(id) });
      queryClient.invalidateQueries({ queryKey: usersQueryKeys.lists() });
      queryClient.invalidateQueries({ queryKey: usersQueryKeys.me() });
      options?.onSuccess?.(data, variables, context);
    },
    ...options
  });
};

export {
  useMe,
  useUser,
  useUsers,
  useUpdateUser,
  useDeleteUser
};
