import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/models/SOAP/get_Allergies_request_model.dart';
import 'package:doctor_app_flutter/models/SOAP/master_key_model.dart';
import 'package:doctor_app_flutter/models/SOAP/post_allergy_request_model.dart';
import 'package:doctor_app_flutter/models/SOAP/post_chief_complaint_request_model.dart';
import 'package:doctor_app_flutter/models/SOAP/post_histories_request_model.dart';

import 'base/lookup-service.dart';

class SOAPService extends LookupService {
  Future getAllergies(GetAllergiesRequestModel getAllergiesRequestModel) async {
    await baseAppClient.post(
      GET_ALLERGIES,
      onSuccess: (dynamic response, int statusCode) {
        listOfAllergies.clear();
        response['List_Allergies']['entityList'].forEach((v) {
          listOfAllergies.add(MasterKeyModel.fromJson(v));
        });
      },
      onFailure: (String error, int statusCode) {
        hasError = true;
        super.error = error;
      },
      body: getAllergiesRequestModel.toJson(),
    );
  }

  Future postAllergy(PostAllergyRequestModel postAllergyRequestModel) async {
    hasError = false;

    await baseAppClient.post(POST_ALLERGY,
        onSuccess: (dynamic response, int statusCode) {
          print("Success");
        }, onFailure: (String error, int statusCode) {
          hasError = true;
          super.error = error;
        }, body: postAllergyRequestModel.toJson());
  }

  Future postHistories(
      PostHistoriesRequestModel postHistoriesRequestModel) async {
    hasError = false;
    await baseAppClient.post(POST_HISTORY,
        onSuccess: (dynamic response, int statusCode) {
          print("Success");
        }, onFailure: (String error, int statusCode) {
          hasError = true;
          super.error = error;
        }, body: postHistoriesRequestModel.toJson());
  }

  Future postChiefComplaint(
      PostChiefComplaintRequestModel postChiefComplaintRequestModel) async {
    hasError = false;
    await baseAppClient.post(POST_CHIEF_COMPLAINT,
        onSuccess: (dynamic response, int statusCode) {
          print("Success");
        }, onFailure: (String error, int statusCode) {
          hasError = true;
          super.error = error;
        }, body: postChiefComplaintRequestModel.toJson());
  }
}
