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/discharge_summary/GetDischargeSummaryReqModel.dart';
import 'package:doctor_app_flutter/core/model/discharge_summary/GetDischargeSummaryResModel.dart';

class DischargeSummaryService extends BaseService {
  List<GetDischargeSummaryResModel> _pendingDischargeSummaryList = [];

  List<GetDischargeSummaryResModel> get pendingDischargeSummaryList => _pendingDischargeSummaryList;

  List<GetDischargeSummaryResModel> _allDischargeSummaryList = [];

  List<GetDischargeSummaryResModel> get allDischargeSummaryList => _allDischargeSummaryList;

  Future getPendingDischargeSummary({GetDischargeSummaryReqModel? getDischargeSummaryReqModel}) async {
    hasError = false;
    await baseAppClient.post(GET_PENDING_DISCHARGE_SUMMARY, onSuccess: (dynamic response, int statusCode) {
      _pendingDischargeSummaryList.clear();
      response['List_PendingDischargeSummary'].forEach(
        (v) {
          _pendingDischargeSummaryList.add(GetDischargeSummaryResModel.fromJson(v));
        },
      );
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: getDischargeSummaryReqModel!.toJson());
  }

  Future getAllDischargeSummary({GetDischargeSummaryReqModel? getDischargeSummaryReqModel}) async {
    hasError = false;
    await baseAppClient.post(GET_ALL_DISCHARGE_SUMMARY, onSuccess: (dynamic response, int statusCode) {
      _allDischargeSummaryList.clear();
      response['List_DischargeSummary'].forEach(
        (v) {
          _allDischargeSummaryList.add(GetDischargeSummaryResModel.fromJson(v));
        },
      );
    }, onFailure: (String error, int statusCode) {
      hasError = true;
      super.error = error;
    }, body: getDischargeSummaryReqModel!.toJson());
  }
}
