import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/service/base/base_service.dart';
import 'package:doctor_app_flutter/core/model/doctor/list_gt_my_patients_question_model.dart';
import 'package:doctor_app_flutter/core/model/doctor/replay/request_create_doctor_response.dart';
import 'package:doctor_app_flutter/core/model/doctor/replay/request_doctor_reply.dart';
import 'package:doctor_app_flutter/core/model/patient/my_referral/my_referral_patient_model.dart';

class DoctorReplyService extends BaseService {
  List<ListGtMyPatientsQuestions> get listDoctorWorkingHoursTable =>
      _listDoctorWorkingHoursTable;

  List<ListGtMyPatientsQuestions> get listDoctorNotRepliedQuestions =>
      _listDoctorNotRepliedQuestions;
  List<ListGtMyPatientsQuestions> _listDoctorWorkingHoursTable = [];
  List<ListGtMyPatientsQuestions> _listDoctorNotRepliedQuestions = [];
  List<MyReferralPatientModel> _listMyReferralPatientModel = [];

  List<MyReferralPatientModel> get listMyReferralPatientModel =>
      _listMyReferralPatientModel;
  int notRepliedCount = 0;

  Future getDoctorReply(RequestDoctorReply _requestDoctorReply,
      {bool clearData = false, bool isGettingNotReply = false}) async {
    hasError = false;
    await baseAppClient.post(
      GT_MY_PATIENT_QUESTION,
      onSuccess: (dynamic response, int statusCode) {
        if (clearData) {
          if (isGettingNotReply)
            _listDoctorNotRepliedQuestions.clear();
          else
            _listDoctorWorkingHoursTable.clear();
        }

        response['List_GtMyPatientsQuestions'].forEach((v) {
          if (isGettingNotReply)
            _listDoctorNotRepliedQuestions
                .add(ListGtMyPatientsQuestions.fromJson(v));
          else
            _listDoctorWorkingHoursTable
                .add(ListGtMyPatientsQuestions.fromJson(v));
        });
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
      body: _requestDoctorReply.toJson(),
    );
  }

  Future createDoctorResponse(
      CreateDoctorResponseModel createDoctorResponseModel) async {
    hasError = false;
    await baseAppClient.post(
      CREATE_DOCTOR_RESPONSE,
      body: createDoctorResponseModel.toJson(),
      onSuccess: (dynamic body, int statusCode) {},
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
    );
  }

  Future getNotRepliedCount() async {
    hasError = false;
    await baseAppClient.post(
      GET_DOCTOR_NOT_REPLIED_COUNTS,
      body: {},
      onSuccess: (dynamic body, int statusCode) {
        notRepliedCount = body["DoctorNotRepliedCounts"];
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
    );
  }
}
