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/model/radiology/final_radiology.dart';
import 'package:diplomaticquarterapp/core/model/radiology/request_send_rad_report_email.dart';
import 'package:diplomaticquarterapp/core/service/base_service.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';

class RadiologyService extends BaseService {
  List<FinalRadiology> finalRadiologyList = List();
  String url = '';

  Future getRadImageURL({int invoiceNo, int lineItem,int projectId}) async {
    hasError = false;
    final Map<String, dynamic> body = new Map<String, dynamic>();
    body['InvoiceNo'] = invoiceNo;
    body['LineItemNo'] = lineItem;
    body['ProjectID'] = projectId;

    await baseAppClient.post(GET_RAD_IMAGE_URL,
        isAllowAny: true,
        onSuccess: (dynamic response, int statusCode) {
      url = response['Data'];
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: body);
  }

  Future getPatientRadOrders () async {
    hasError = false;
    await baseAppClient.post(GET_PATIENT_ORDERS,
        onSuccess: (dynamic response, int statusCode) {
      finalRadiologyList.clear();
      response['FinalRadiologyList'].forEach((radiology) {
        finalRadiologyList.add(FinalRadiology.fromJson(radiology));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: Map());
  }

  Future getPatientRadOrdersDetails() async {
    hasError = false;
    await baseAppClient.post(GET_PATIENT_ORDERS,
        onSuccess: (dynamic response, int statusCode) {
      finalRadiologyList.clear();
      response['FinalRadiologyList'].forEach((radiology) {
        finalRadiologyList.add(FinalRadiology.fromJson(radiology));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: Map());
  }

  RequestSendRadReportEmail _requestSendRadReportEmail =
      RequestSendRadReportEmail();

  Future sendRadReportEmail(
      {FinalRadiology finalRadiology}) async {
    _requestSendRadReportEmail.projectID = finalRadiology.projectID;
    _requestSendRadReportEmail.clinicName = finalRadiology.clinicDescription;
    _requestSendRadReportEmail.invoiceNo = finalRadiology.invoiceNo;
    _requestSendRadReportEmail.setupID = finalRadiology.setupID;
    _requestSendRadReportEmail.doctorName = finalRadiology.doctorName;
    _requestSendRadReportEmail.orderDate = '${finalRadiology.orderDate.year}-${finalRadiology.orderDate.month}-${finalRadiology.orderDate.day}';
    _requestSendRadReportEmail.patientIditificationNum = '2344670985';//TODO change it
    _requestSendRadReportEmail.patientMobileNumber = '537503378';//TODO change it
    _requestSendRadReportEmail.patientName = 'TAMER FANASHE';//TODO change it
    _requestSendRadReportEmail.patientIditificationNum = '2344670985';//TODO change it
    _requestSendRadReportEmail.projectName = finalRadiology.projectName;
    _requestSendRadReportEmail.radResult = 'asd';//finalRadiology.reportData;
    _requestSendRadReportEmail.to = 'Tamer.fanasheh@gmail.com';
    _requestSendRadReportEmail.dateofBirth = '/Date(536743800000+0300)/';

    hasError = false;
    await baseAppClient.post(SEND_RAD_REPORT_EMAIL,
        isAllowAny: true,
        onSuccess: (dynamic response, int statusCode) {

        },
        onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: _requestSendRadReportEmail.toJson());
  }
}
