import 'package:hmg_patient_app_new/core/enums.dart';
import 'package:hmg_patient_app_new/features/authentication/models/request_models/send_activation_request_model.dart';

class RequestUtils {
  static dynamic getPatientAuthenticationRequest({
    required String phoneNumber,
    required String nationId,
    required OTPTypeEnum otpTypeEnum,
    required bool patientOutSA,
    required bool isForRegister,
    required int? patientId,
    required String zipCode,
  }) {
    bool fileNo = false;
    if (nationId.isNotEmpty) {
      fileNo = nationId.length < 10;
    }
    var request = SendActivationRequest();
    if (phoneNumber.isNotEmpty) {
      request.patientMobileNumber = int.parse(phoneNumber);
    }
    request.oTPSendType = otpTypeEnum.toInt(); // could map OTPTypeEnum if needed
    request.zipCode = zipCode; // or countryCode if defined elsewhere

    if (isForRegister) {
      // request.searchType = registeredData.searchType ?? 1;
      // request.patientID = registeredData.patientID ?? 0;
      // request.patientIdentificationID = request.nationalID = registeredData.patientIdentificationID ?? '0';
      // request.dob = registeredData.dob;
      // request.isRegister = registeredData.isRegister;
    } else {
      if (fileNo) {
        request.patientID = patientId ?? int.parse(nationId);
        request.patientIdentificationID = request.nationalID = "";
        request.searchType = 2;
      } else {
        request.patientID = 0;
        request.searchType = 1;
        request.patientIdentificationID = request.nationalID = nationId.isNotEmpty ? nationId : '0';
      }
      request.isRegister = false;
    }
    return request;
  }

  static dynamic getCommonRequestWelcome({
    required String phoneNumber,
    required OTPTypeEnum otpTypeEnum,
    required String? deviceToken,
    required bool patientOutSA,
    required String? loginTokenID,
    required var registeredData,
    required int? patientId,
    required String nationIdText,
    required String countryCode,
  }) {
    bool fileNo = false;
    if (nationIdText.isNotEmpty) {
      fileNo = nationIdText.length < 10;
    }
    var request = SendActivationRequest();
    request.patientMobileNumber = int.parse(phoneNumber);
    request.mobileNo = '0$phoneNumber';
    request.deviceToken = deviceToken;
    request.projectOutSA = patientOutSA;
    request.loginType = otpTypeEnum.toInt();
    request.oTPSendType = otpTypeEnum.toInt(); // could map OTPTypeEnum if needed
    request.zipCode = countryCode; // or countryCode if defined elsewhere
    request.logInTokenID = loginTokenID ?? "";

    if (registeredData != null) {
      request.searchType = registeredData.searchType ?? 1;
      request.patientID = registeredData.patientID ?? 0;
      request.patientIdentificationID = request.nationalID = registeredData.patientIdentificationID ?? '0';
      request.dob = registeredData.dob;
      request.isRegister = registeredData.isRegister;
    } else {
      if (fileNo) {
        request.patientID = patientId ?? int.parse(nationIdText);
        request.patientIdentificationID = request.nationalID = "";
        request.searchType = 2;
      } else {
        request.patientID = 0;
        request.searchType = 1;
        request.patientIdentificationID = request.nationalID = nationIdText.isNotEmpty ? nationIdText : '0';
      }
      request.isRegister = false;
    }

    request.deviceTypeID = request.searchType;
    return request;
  }

  static getCommonRequestSendActivationCode({
    required OTPTypeEnum otpTypeEnum,
    required String mobileNumber,
    required String zipCode,
    required int? patientId,
    required String? nationalId,
    required bool patientOutSA,
    required int selectedLoginType,
    required bool isForRegister,
    required bool isFileNo,
  }) {
    var request = SendActivationRequest();
    if (mobileNumber.isNotEmpty) {
      request.patientMobileNumber = int.parse(mobileNumber);
    }
    request.mobileNo = '0$mobileNumber';
    request.projectOutSA = patientOutSA;
    request.loginType = selectedLoginType;
    request.oTPSendType = otpTypeEnum.toInt(); //this.selectedOption == 1 ? 1 : 2;
    request.zipCode = zipCode;

    if (isForRegister) {
      // request.searchType = registeredData.searchType ?? 1;
      // request.patientID = registeredData.patientID ?? 0;
      // request.patientIdentificationID = request.nationalID = registeredData.patientIdentificationID ?? '0';
      // request.dob = registeredData.dob;
      // request.isRegister = registeredData.isRegister;
    } else {
      request.searchType = isFileNo ? 2 : 1;
      request.patientID = patientId ?? 0;
      request.nationalID = nationalId ?? '0';
      request.patientIdentificationID = nationalId ?? '0';
      request.isRegister = false;
    }
    request.deviceTypeID = request.searchType;
    return request;
  }
}
