import ApiService from './ApiService';

export async function apiSignIn(data) {
  return ApiService.fetchData({
    url: '/gateway/UsersAuth/login',
    method: 'post',
    data,
  });
}

export async function apiSignUp(data,) {

  return ApiService.fetchData({
    url: '/gateway/Registration',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}

export async function apiSignOut(data) {
  return ApiService.fetchData({
    url: '/gateway/UsersAuth/signout',
    method: 'post',
    data,
  });
}

export async function apiForgotPassword(data) {
  return ApiService.fetchData({
    url: '/gateway/Users/ForgetPassword',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}

export async function apiResetPassword(data) {
  return ApiService.fetchData({
    url: '/reset-password',
    method: 'post',
    data,
  });
}

export async function apiSendOTP(data, phoneNumber) {
  if (data.dialCode && data.mobileNumber) {
    data.PhoneNumber = data.dialCode + data.mobileNumber;
  }
  return ApiService.fetchData({
    url: '/gateway/Users/ForgetPassword',
    method: 'post',
    data: { PhoneNumber: data.PhoneNumber || phoneNumber },
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}

export async function apiVerifyOTP(data, phoneNumber) {
  if (data.dialCode && data.mobileNumber) {
    data.PhoneNumber = data.dialCode + data.mobileNumber;
  }
  return ApiService.fetchData({
    url: '/gateway/Common/VerificationCode',
    method: 'post',
    data: { PhoneNumber: data.PhoneNumber || phoneNumber, VerificationCode: data.verificationCode },
    // headers: {
    //   'Content-Type': 'multipart/form-data',
    // },
  });
}

export async function apiNewPassword(data, phoneNumber) {
  if (data.dialCode && data.mobileNumber) {
    data.PhoneNumber = data.dialCode + data.mobileNumber;
  }
  if (data.newPassword !== data.confirmPassword) {
    return { status: 400, message: 'Password and Confirm Password does not match' };
  }

  return ApiService.fetchData({
    url: '/gateway/Users/AddNewPassword',
    method: 'post',
    data: {
      PhoneNumber: data.PhoneNumber || phoneNumber,
      Password: data.newPassword,
      ConfirmPassword: data.confirmPassword,
    },
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}
