/**
 * Password Service
 * Handles forgot password and reset password API calls
 */

import http from '@/http';

/**
 * Request a password reset email
 * Always resolves successfully (API returns 200 regardless of email existence)
 */
export async function forgotPassword(email: string): Promise<void> {
  if (!email || email.trim() === '') {
    throw new Error('Email is required');
  }

  await http.post('/forgot-password/front', { email });
}

/**
 * Reset password with a valid token
 */
export async function resetPassword(token: string, newPassword: string): Promise<void> {
  if (!token || token.trim() === '') {
    throw new Error('Token is required');
  }

  if (!newPassword || newPassword.trim() === '') {
    throw new Error('New password is required');
  }

  if (newPassword.length < 8) {
    throw new Error('Password must be at least 8 characters');
  }

  await http.post('/reset-password/front', { token, newPassword });
}
