import * as api from "../service/AdminService";
import { useMutation, useQuery } from "@tanstack/react-query";

export const useGetAdmins = (page: number = 1, limit: number = 10) => {
  return useQuery({
    queryKey: ["admins", page, limit],
    queryFn: () => api.getAdmins(page, limit),
  });
};

export const useGetPermissions = () => {
  return useQuery({
    queryKey: ["permissions"],
    queryFn: () => api.getPermissions(),
  });
};

export const useCreateAdmin = () => {
  return useMutation({
    mutationFn: api.createAdmin,
  });
};

export const useDeleteAdmin = () => {
  return useMutation({
    mutationFn: api.deleteAdmin,
  });
};

export const useGetAdminDetail = (id: string) => {
  return useQuery({
    queryKey: ["admin", id],
    queryFn: () => api.getAdminDetail(id),
    enabled: !!id,
  });
};

export const useUpdateAdmin = () => {
  return useMutation({
    mutationFn: api.updateAdmin,
  });
};
