import { axios, handleApiError } from ".";

export const requestEmailOtpApi = async (): Promise<void> => {
  const response = await axios.post("/api/v1/auth/email");

  if (response.status !== 200 && response.status !== 201)
    throw await handleApiError(response);

  return response.data;
};

export interface ConfirmEmailRequest {
  otp: string;
}

export const confirmEmailApi = async (
  req: ConfirmEmailRequest,
): Promise<void> => {
  const response = await axios.post("/api/v1/auth/email/otp", req);

  if (response.status !== 200 && response.status !== 201)
    throw await handleApiError(response);

  return response.data;
};

export const finishVerificationApi = async (): Promise<void> => {
  const response = await axios.post("/api/v1/auth/verify");

  if (response.status !== 200 && response.status !== 201)
    throw await handleApiError(response);

  return response.data;
};
