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/list_gt_my_patients_question_model.dart';
import 'package:doctor_app_flutter/models/doctor/request_add_referred_doctor_remarks.dart';
import 'package:doctor_app_flutter/models/doctor/request_doctor_reply.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';

class DoctorReplyService extends BaseService {

  List<ListGtMyPatientsQuestions> get listDoctorWorkingHoursTable => _listDoctorWorkingHoursTable;
  List<ListGtMyPatientsQuestions> _listDoctorWorkingHoursTable = [];


  RequestDoctorReply _requestDoctorReply = RequestDoctorReply();
  List<MyReferralPatientModel> _listMyReferralPatientModel = [];
  List<MyReferralPatientModel> get listMyReferralPatientModel => _listMyReferralPatientModel;

  Future getDoctorReply() async {
    hasError = false;
    await baseAppClient.post(GT_MY_PATIENT_QUESTION,
        onSuccess: (dynamic response, int statusCode) {
          _listDoctorWorkingHoursTable.clear();
      response['List_GtMyPatientsQuestions'].forEach((v) {
        _listDoctorWorkingHoursTable
            .add(ListGtMyPatientsQuestions.fromJson(v));
      });
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: _requestDoctorReply.toJson(),);
  }

  Future replay(
      String referredDoctorRemarks, ListGtMyPatientsQuestions model) async {
    RequestMyReferralPatientModel _requestMyReferralPatient =
    RequestMyReferralPatientModel();
    RequestAddReferredDoctorRemarks _requestAddReferredDoctorRemarks =
    RequestAddReferredDoctorRemarks();

    _requestAddReferredDoctorRemarks.admissionNo = model.admissionNo.toString();
    _requestAddReferredDoctorRemarks.patientID = model.patientID;
    _requestAddReferredDoctorRemarks.referredDoctorRemarks =
        referredDoctorRemarks;
    _requestAddReferredDoctorRemarks.lineItemNo = model.lineItemNo;
    _requestAddReferredDoctorRemarks.referringDoctor = model.referringDoctor;
    await baseAppClient.post(
      ADD_REFERRED_DOCTOR_REMARKS,
      body: _requestAddReferredDoctorRemarks.toJson(),
      onSuccess: (dynamic body, int statusCode) {
        print("succsss");
        // model.referredDoctorRemarks = referredDoctorRemarks;
        // listMyReferralPatientModel[listMyReferralPatientModel.indexOf(model)] =
        //     model;
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
    );
  }
}
