import { signUp, signIn, signOut, getCurrentUser, resetPassword } from '@crafted/auth';
import type { RegisterInput, LoginInput, ResetPasswordInput } from '@crafted/validators';

export const registerUser = async (input: RegisterInput) => {
  const data = await signUp(input);
  return {
    user: data.user,
    session: data.session,
  };
};

export const loginUser = async (input: LoginInput) => {
  const data = await signIn(input);
  return {
    user: data.user,
    session: data.session,
  };
};

export const logoutUser = async () => {
  await signOut();
  return { success: true };
};

export const getCurrentUserProfile = async () => {
  const user = await getCurrentUser();
  return user;
};

export const sendPasswordReset = async (input: ResetPasswordInput) => {
  await resetPassword(input.email);
  return { success: true };
};
