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

export const useCreateDomain = () => {
  return useMutation({
    mutationFn: (variables: CreateDomainType) => api.createDomain(variables),
  });
};

export const useGetDomains = () => {
  return useQuery({
    queryKey: ["domains"],
    queryFn: () => api.getDomains(),
  });
};

export const useGetDnsRecords = (disabled?: boolean) => {
  return useQuery({
    queryKey: ["dns-records"],
    queryFn: () => api.getDnsRecords(),
    refetchInterval: 3000,
    enabled: !disabled,
  });
};

export const useVerifyDnsRecord = () => {
  return useQuery({
    queryKey: ["verify-dns-record"],
    queryFn: () => api.verifyDnsRecord(),
  });
};

export const useGetSpace = () => {
  return useQuery({
    queryKey: ["space"],
    queryFn: () => api.getSpace(),
  });
};
