import 'package:diplomaticquarterapp/config/config.dart';
import 'package:diplomaticquarterapp/core/model/doctor/doctor_profile.dart';
import 'package:diplomaticquarterapp/core/model/doctor/doctor_rating.dart';
import 'package:diplomaticquarterapp/core/model/doctor/patient_doctor_appointment.dart';
import 'package:diplomaticquarterapp/core/model/doctor/reques_patient_doctor_appointmentt.dart';
import 'package:diplomaticquarterapp/core/model/doctor/request_doctor_profile.dart';
import 'package:diplomaticquarterapp/core/model/doctor/request_doctor_rating.dart';
import 'package:diplomaticquarterapp/core/model/labs/patient_lab_orders.dart';
import 'package:diplomaticquarterapp/core/model/labs/patient_lab_special_result.dart';
import 'package:diplomaticquarterapp/core/model/labs/request_patient_lab_orders.dart';
import 'package:diplomaticquarterapp/core/model/labs/request_patient_lab_special_result.dart';
import 'package:diplomaticquarterapp/core/model/labs/request_send_lab_report_email.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';

class LabsService extends BaseService {


  RequestPatientLabOrders _requestPatientLabOrders = RequestPatientLabOrders();
  List<PatientLabOrders> patientLabOrdersList = List();


  Future getPatientLabOrdersList() async {
    await baseAppClient.post(GET_Patient_LAB_ORDERS,
        onSuccess: (dynamic response, int statusCode) {
          patientLabOrdersList.clear();
          response['ListPLO'].forEach((hospital) {
            patientLabOrdersList
                .add(PatientLabOrders.fromJson(hospital));
          });
        }, onFailure: (String error, int statusCode) {
          hasError = true;
          super.error = error;
        }, body: _requestPatientLabOrders.toJson());
  }


  RequestPatientLabSpecialResult _requestPatientLabSpecialResult = RequestPatientLabSpecialResult();


  List<PatientLabSpecialResult> patientLabSpecialResult = List();

  Future getLaboratoryResult(
      {String projectID, int clinicID, String invoiceNo, String orderNo}) async {
      hasError = false;
    _requestPatientLabSpecialResult.projectID = projectID;
    _requestPatientLabSpecialResult.clinicID = clinicID;
    _requestPatientLabSpecialResult.invoiceNo = invoiceNo;//'1800296522';//;
    _requestPatientLabSpecialResult.orderNo = orderNo;

    await baseAppClient.post(GET_Patient_LAB_SPECIAL_RESULT,
        onSuccess: (dynamic response, int statusCode) {
          patientLabSpecialResult.clear();
          response['ListPLSR'].forEach((hospital) {
            patientLabSpecialResult
                .add(PatientLabSpecialResult.fromJson(hospital));
          });
        }, onFailure: (String error, int statusCode) {
          hasError = true;
          super.error = error;
        }, body: _requestPatientLabSpecialResult.toJson());
  }

  RequestSendLabReportEmail _requestSendLabReportEmail = RequestSendLabReportEmail();

  Future sendLabReportEmail(
      {PatientLabOrders patientLabOrder}) async {

    _requestSendLabReportEmail.projectID = patientLabOrder.projectID;
    _requestSendLabReportEmail.invoiceNo = patientLabOrder.invoiceNo;
    _requestSendLabReportEmail.doctorName = patientLabOrder.doctorName;
    _requestSendLabReportEmail.clinicName = patientLabOrder.clinicDescription;
    _requestSendLabReportEmail.patientName = 'Tamer';//TODO Change it
    _requestSendLabReportEmail.patientIditificationNum = '2344670985';//TODO change it
    _requestSendLabReportEmail.dateofBirth = '/Date(536743800000+0300)/';//TODO change it
    _requestSendLabReportEmail.to = 'Tamer.fanasheh@gmail.com';//TODO change it
    _requestSendLabReportEmail.orderDate = '${patientLabOrder.orderDate.year}-${patientLabOrder.orderDate.month}-${patientLabOrder.orderDate.day}';
    _requestSendLabReportEmail.patientMobileNumber = '537503378';//TODO change it
    _requestSendLabReportEmail.projectName = patientLabOrder.projectName;

    await baseAppClient.post(GET_Patient_LAB_SPECIAL_RESULT,
        onSuccess: (dynamic response, int statusCode) {
          AppToast.showSuccessToast(message: 'A copy has been sent to the email');
        }, onFailure: (String error, int statusCode) {
          hasError = true;
          super.error = error;
        }, body: _requestSendLabReportEmail.toJson());
  }


}
