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/pharmacy-intervention-model/accept_or_reject_req_model.dart';
import 'package:doctor_app_flutter/core/model/pharmacy-intervention-model/intervention_medication_history_req_model.dart';
import 'package:doctor_app_flutter/core/model/pharmacy-intervention-model/intervention_medication_history_res_model.dart';
import 'package:doctor_app_flutter/core/model/pharmacy-intervention-model/new_medication_req_model.dart';
import 'package:doctor_app_flutter/core/model/pharmacy-intervention-model/new_medication_res_model.dart';
class InterventionMedicationService extends BaseService {

  List<InterventionMedicationResModel> _allInterventionList = [];

  List<InterventionMedicationHistoryResModel> _allInterventionHistoryList = [];

  List<InterventionMedicationResModel> get allInterventionList =>
      _allInterventionList;

  List<InterventionMedicationHistoryResModel> get allInterventionHistoryList =>
      _allInterventionHistoryList;

  Future getInterventionMedication(
      {InterventionMedicationReqModel? interventionMedicationReqModel}) async {
    hasError = false;
    await baseAppClient.post(GET_INTERVENTION_MEDICATION,
        onSuccess: (dynamic response, int statusCode) {
          _allInterventionList.clear();
          response['List_InterventionMedications'].forEach(
                (v) {
              _allInterventionList.add(InterventionMedicationResModel.fromJson(v));
            },
          );
        }, onFailure: (String error, int statusCode) {
          hasError = true;
          super.error = error;
        }, body: interventionMedicationReqModel!.toJson());
  }

  Future getInterventionMedicationHistory(
      {InterventionMedicationHistoryReqModel? interventionMedicationHistoryReqModel}) async {
    hasError = false;
    await baseAppClient.post(GET_INTERVENTION_MEDICATION_HISTORY,
        onSuccess: (dynamic response, int statusCode) {
          _allInterventionHistoryList.clear();
          response['List_InterventionHistory'].forEach(
                (v) {
                  _allInterventionHistoryList.add(InterventionMedicationHistoryResModel.fromJson(v));
            },
          );
        }, onFailure: (String error, int statusCode) {
          hasError = true;
          super.error = error;
        }, body: interventionMedicationHistoryReqModel!.toJson());
  }

  Future setAcceptedOrRejected(
      {AcceptOrRejectReqModel? acceptOrRejectReqModel}) async {
    hasError = false;
    await baseAppClient.post(SET_ACCEPTED_OR_REJECTED,
        onSuccess: (dynamic response, int statusCode) {
          _allInterventionHistoryList.clear();

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