import 'package:doctor_app_flutter/config/config.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';
import 'package:doctor_app_flutter/models/patient/my_referral/my_referral_patient_model.dart';
import 'package:doctor_app_flutter/models/patient/request_my_referral_patient_model.dart';
import 'package:doctor_app_flutter/util/helpers.dart';

class ReferralPatientService extends BaseService {

  List<MyReferralPatientModel> _listMyReferralPatientModel = [];
  List<MyReferralPatientModel> get listMyReferralPatientModel => _listMyReferralPatientModel;


  Helpers helpers = Helpers();


  RequestMyReferralPatientModel _requestMyReferralPatient = RequestMyReferralPatientModel();
  RequestAddReferredDoctorRemarks _requestAddReferredDoctorRemarks = RequestAddReferredDoctorRemarks();

  Future getMyReferralPatient() async {
    await baseAppClient.post(GET_MY_REFERRAL_PATIENT,
        onSuccess: (dynamic response, int statusCode) {
          _listMyReferralPatientModel.clear();
          response['List_MyReferralPatient'].forEach((v) {
            listMyReferralPatientModel.add(MyReferralPatientModel.fromJson(v));
          });
          print(response['List_MyReferralPatient']);
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: _requestMyReferralPatient .toJson(),);
  }

  Future replay(
      String referredDoctorRemarks, MyReferralPatientModel model) async {

    _requestAddReferredDoctorRemarks.admissionNo = model.admissionNo;
    _requestAddReferredDoctorRemarks.patientID = model.patientID;
    _requestAddReferredDoctorRemarks.referredDoctorRemarks = referredDoctorRemarks;
    _requestAddReferredDoctorRemarks.lineItemNo = model.lineItemNo;
    _requestAddReferredDoctorRemarks.referringDoctor = model.referringDoctor;
    await baseAppClient.post(GET_MY_REFERRAL_PATIENT,
        onSuccess: (dynamic response, int statusCode) {
          model.referredDoctorRemarks = referredDoctorRemarks;
          listMyReferralPatientModel[
          listMyReferralPatientModel.indexOf(model)] = model;
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: _requestMyReferralPatient .toJson(),);
  }
}
