import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/model/MyReferralPatientModel.dart';
import 'package:doctor_app_flutter/core/service/base/base_service.dart';
import 'package:doctor_app_flutter/models/doctor/request_add_referred_doctor_remarks.dart';

class MyReferralInPatientService extends BaseService {
  List<MyReferralPatientModel> myReferralPatients = List();

  Future getMyReferralPatientService() async {
    hasError = false;
    Map<String, dynamic> body = Map();
    await getDoctorProfile();
    body['DoctorID'] = doctorProfile.doctorID;
    body['FirstName'] = "0";
    body['MiddleName'] = "0";
    body['LastName'] = "0";
    body['PatientMobileNumber'] = "0";
    body['PatientIdentificationID'] = "0";
    body['PatientID'] = 0;
    body['From'] = "0";
    body['To'] = "0";
    body['stamp'] = DateTime.now().toIso8601String();
    body['IsLoginForDoctorApp'] = true;
    body['IPAdress'] = "11.11.11.11";
    body['PatientOutSA'] = false;
    body['PatientTypeID'] = 1;
    myReferralPatients.clear();
    await baseAppClient.post(
      GET_MY_REFERRAL_INPATIENT,
      onSuccess: (dynamic response, int statusCode) {
        if (response['List_MyReferralPatient'] != null) {
          response['List_MyReferralPatient'].forEach((v) {
            myReferralPatients.add(MyReferralPatientModel.fromJson(v));
          });
        }
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
      body: body,
    );
  }

  Future replay(String referredDoctorRemarks, MyReferralPatientModel referral) async {
    hasError = false;
    await getDoctorProfile();
    RequestAddReferredDoctorRemarks _requestAddReferredDoctorRemarks = RequestAddReferredDoctorRemarks();
    _requestAddReferredDoctorRemarks.projectID = referral.projectID;
    _requestAddReferredDoctorRemarks.admissionNo = referral.admissionNo.toString();
    _requestAddReferredDoctorRemarks.lineItemNo = referral.lineItemNo;
    _requestAddReferredDoctorRemarks.referredDoctorRemarks = referredDoctorRemarks;
    _requestAddReferredDoctorRemarks.editedBy = doctorProfile.doctorID;
    _requestAddReferredDoctorRemarks.patientID = referral.patientID;
    _requestAddReferredDoctorRemarks.referringDoctor = referral.referringDoctor;
    await baseAppClient.post(
      ADD_REFERRED_DOCTOR_REMARKS,
      body: _requestAddReferredDoctorRemarks.toJson(),
      onSuccess: (dynamic body, int statusCode) {
        
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
    );
  }
}
