import 'package:hmg_patient_app/config/config.dart';
import 'package:hmg_patient_app/core/model/eye/AppoimentAllHistoryResult.dart';
import 'package:hmg_patient_app/core/service/base_service.dart';
import 'package:hmg_patient_app/uitl/utils.dart';

class EyeService extends BaseService {
  List<AppoimentAllHistoryResultList> appoimentAllHistoryResultList = [];

  getEyeMeasurement() async {
    hasError = false;
    super.error = "";
    Map<String, dynamic> body = Map();
    body['isDentalAllowedBackend'] = false;
    body['IsIrisPrescription'] = true;
    await baseAppClient.post(GET_PATIENT_APPOINTMENT_HISTORY, onSuccess: (response, statusCode) async {
      appoimentAllHistoryResultList.clear();
      response['AppoimentAllHistoryResultList'].forEach((appoitment) {
        appoimentAllHistoryResultList.add(AppoimentAllHistoryResultList.fromJson(appoitment));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  sendGlassesPrescriptionEmail({int? appointmentNo, String? projectName, int? projectID}) async {
    hasError = false;
    super.error = "";
    Map<String, dynamic> body = Map();
    body['isDentalAllowedBackend'] = false;
    body['PatientIditificationNum'] = user.patientIdentificationNo;
    body['PatientName'] = user.firstName! + " " + user.lastName!;
    body['To'] = user.emailAddress;
    body['SetupID'] = user.setupID;
    body['DateofBirth'] = user.dateofBirth;
    body['ProjectID'] = projectID;
    body['AppointmentNo'] = appointmentNo;
    body['ProjectName'] = projectName;
    body['PatientID'] = user.patientID;
    body['PatientMobileNumber'] = Utils.getPhoneNumberWithoutZero(user.mobileNumber!);
    await baseAppClient.post(SEND_REPORT_EYE_EMAIL, onSuccess: (response, statusCode) async {}, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  sendContactLensPrescriptionEmail({int? appointmentNo, String? projectName, int? projectID}) async {
    hasError = false;
    super.error = "";
    Map<String, dynamic> body = Map();
    body['isDentalAllowedBackend'] = false;
    body['AppointmentNo'] = appointmentNo;
    body['PatientIditificationNum'] = user.patientIdentificationNo;
    body['PatientName'] = user.firstName! + " " + user.lastName!;
    body['To'] = user.emailAddress;
    body['SetupID'] = user.setupID;
    body['DateofBirth'] = user.dateofBirth;
    body['ProjectID'] = projectID;
    body['AppointmentNo'] = appointmentNo;
    body['ProjectName'] = projectName;
    body['PatientID'] = user.patientID;
    body['PatientMobileNumber'] = Utils.getPhoneNumberWithoutZero(user.mobileNumber!);
    await baseAppClient.post(SEND_CONTACT_LENS_PRESCRIPTION_EMAIL, onSuccess: (response, statusCode) async {}, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }
}
