import axios from "../../../config/axios";
import {
  ChangePasswordType,
  UpdateSettingType,
  TwoFactorSetupResponseType,
  TwoFactorEnableResponseType,
} from "../types/SettingTypes";

export const getSettings = async () => {
  const { data } = await axios.get(`/settings`);
  return data;
};

export const updateSettings = async (params: UpdateSettingType) => {
  await axios.patch(`/settings/${params.id}/toggle`, params);
};

export const changePassword = async (params: ChangePasswordType) => {
  await axios.patch(`/auth/change-password`, params);
};

export const setupTwoFactor = async (): Promise<TwoFactorSetupResponseType> => {
  const { data } = await axios.post(`/auth/2fa/setup`);
  return data;
};

export const enableTwoFactor = async (
  token: string
): Promise<TwoFactorEnableResponseType> => {
  const { data } = await axios.post(`/auth/2fa/enable`, { token });
  return data;
};

export const disableTwoFactor = async (
  token: string
): Promise<TwoFactorEnableResponseType> => {
  const { data } = await axios.post(`/auth/2fa/disable  `, { token });
  return data;
};
