import { useMutation, useQuery } from "@tanstack/react-query";
import * as api from "../service/SettingService";
import {
  ChangePasswordType,
  UpdateSettingType,
  TwoFactorSetupResponseType,
  TwoFactorEnableResponseType,
} from "../types/SettingTypes";

export const useGetSettings = () => {
  return useQuery({
    queryKey: ["settings"],
    queryFn: () => api.getSettings(),
  });
};

export const useUpdateSetting = () => {
  return useMutation({
    mutationFn: (variables: UpdateSettingType) => api.updateSettings(variables),
  });
};

export const useChangePassword = () => {
  return useMutation({
    mutationFn: (variables: ChangePasswordType) =>
      api.changePassword(variables),
  });
};

export const useSetupTwoFactor = () => {
  return useMutation<TwoFactorSetupResponseType>({
    mutationFn: () => api.setupTwoFactor(),
  });
};

export const useEnableTwoFactor = () => {
  return useMutation<TwoFactorEnableResponseType, Error, string>({
    mutationFn: (token: string) => api.enableTwoFactor(token),
  });
};

export const useDisableTwoFactor = () => {
  return useMutation<TwoFactorEnableResponseType, Error, string>({
    mutationFn: (token: string) => api.disableTwoFactor(token),
  });
};
