import axios from 'axios';

const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4000';


export const iamAuthApi = {
  // `identifier` can be an email address or a phone number — the IAM accepts
  // either in the `email` field of the forgot-password body.
  forgotPassword: (identifier: string) =>
    axios.post(`${API_URL}/v1/auth/forgot-password`, { email: identifier }),

  resetPassword: (data: {
    userId: string;
    email: string;
    verificationCode: string;
    newPassword: string;
    confirmPassword: string;
  }) => axios.patch(`${API_URL}/v1/auth/set-password`, data),

  changePassword: (data: {
    oldPassword: string;
    newPassword: string;
    confirmPassword: string;
  }) =>
    axios.patch(`${API_URL}/v1/auth/change-password`, data, {
      headers: { Authorization: `Bearer ${localStorage.getItem('auth_token')}` },
    }),
};
