import 'package:dio/dio.dart';

class ChangePasswordService {
  final Dio _dio;

  ChangePasswordService(this._dio);

  Future getOtp({
    required String mobileNumber,
  }) async {
    final response = await _dio.post(
      '/api/otp/send',
      data: {'mobileNumber': mobileNumber, 'type': "CHANGE_LPWORD"},
    );
    if (response.statusCode != 200) {
      throw Exception("Invalid Mobile Number/Type");
    }
    print(response.toString());
    return response.toString();
  }

  Future getOtpTpin({
    required String mobileNumber,
  }) async {
    final response = await _dio.post(
      '/api/otp/send',
      data: {'mobileNumber': mobileNumber, 'type': "CHANGE_TPIN"},
    );
    if (response.statusCode != 200) {
      throw Exception("Invalid Mobile Number/Type");
    }
    print(response.toString());
    return response.toString();
  }

  Future validateOtp({
    required String otp,
    required String mobileNumber,
  }) async {
    final response = await _dio.post(
      '/api/otp/verify?mobileNumber=$mobileNumber',
      data: {
        'otp': otp,
      },
    );
    if (response.statusCode != 200) {
      throw Exception("Wrong OTP");
    }
    return response.toString();
  }

  Future validateChangePwd({
    required String OldLPsw,
    required String newLPsw,
    required String confirmLPsw,
  }) async {
    final response = await _dio.post(
      '/api/auth/change/login_password',
      data: {
        'OldLPsw': OldLPsw,
        'newLPsw': newLPsw,
        'confirmLPsw': confirmLPsw,
      },
    );
    if (response.statusCode != 200) {
      throw Exception("Wrong OTP");
    }
    return response.toString();
  }

  Future validateChangeTpin({
    required String oldTpin,
    required String newTpin,
  }) async {
    final response = await _dio.post(
      '/api/auth/change/tpin',
      data: {
        'oldTpin': oldTpin,
        'newTpin': newTpin,
      },
    );
    if (response.statusCode != 200) {
      throw Exception("Wrong OTP");
    }
    return response.toString();
  }
}
