import 'dart:core';

import 'package:hmg_patient_app/core/enum/viewstate.dart';
import 'package:hmg_patient_app/core/model/AlHabibMedicalService/EReferral/check_activation_code_for_e_referral_request_model.dart';
import 'package:hmg_patient_app/core/model/AlHabibMedicalService/EReferral/create_e_referral_request_model.dart';
import 'package:hmg_patient_app/core/model/AlHabibMedicalService/EReferral/get_all_cities_response_model.dart';
import 'package:hmg_patient_app/core/model/AlHabibMedicalService/EReferral/get_all_relationship_types_response_model.dart';
import 'package:hmg_patient_app/core/model/AlHabibMedicalService/EReferral/search_e_referral_request_model.dart';
import 'package:hmg_patient_app/core/model/AlHabibMedicalService/EReferral/search_e_referral_response_model.dart';
import 'package:hmg_patient_app/core/model/AlHabibMedicalService/EReferral/send_activation_code_for_e_referral_request_model.dart';
import 'package:hmg_patient_app/core/service/AlHabibMedicalService/e_referral_service.dart';

import '../../../locator.dart';
import '../base_view_model.dart';

class EReferralViewModel extends BaseViewModel {
  EReferralService _eReferralService = locator<EReferralService>();

  List<GetAllRelationshipTypeResponseModel> get relationTypes =>
      _eReferralService.relationTypes;
  List<GetAllCitiesResponseModel> get allCities => _eReferralService.allCities;
  List<SearchEReferralResponseModel> get allReferral => _eReferralService.allReferral;

  String get referralNumber => _eReferralService.referralNumber;

  void  getRelationTypes() async {
    setState(ViewState.Busy);
    await _eReferralService.getRelationTypes();
    if (_eReferralService.hasError) {
      error = _eReferralService.error!;
      setState(ViewState.Error);
    } else{
      setState(ViewState.Idle);
    }
  }
  void  getAllCities() async {
    setState(ViewState.Busy);
    await _eReferralService.getAllCities();
    if (_eReferralService.hasError) {
      error = _eReferralService.error!;
      setState(ViewState.Error);
    } else{
      setState(ViewState.Idle);
    }
  }

  void getAllProjects() async {

  }
//Changed By Aamir into Future<void>
  Future<void>  sendActivationCodeForEReferral(SendActivationCodeForEReferralRequestModel sendActivationCodeForEReferralRequestModel) async {
    setState(ViewState.BusyLocal);
    await _eReferralService.sendActivationCodeForEReferral(sendActivationCodeForEReferralRequestModel);
    if (_eReferralService.hasError) {
      error = _eReferralService.error!;
      setState(ViewState.ErrorLocal);
    } else{
      setState(ViewState.Idle);
    }
  }

    checkActivationCodeForEReferral(CheckActivationCodeForEReferralResponseModel checkActivationCodeForEReferralRequestModel) async {
    setState(ViewState.BusyLocal);
    await _eReferralService.checkActivationCodeForEReferral(checkActivationCodeForEReferralRequestModel);
    if (_eReferralService.hasError) {
      error = _eReferralService.error!;
      setState(ViewState.ErrorLocal);
    } else{
      setState(ViewState.Idle);
    }
  }
//Changed by Aamir to Future
  Future<void> createEReferral(
      CreateEReferralRequestModel createEReferralRequestModel) async {
    setState(ViewState.BusyLocal);
    await _eReferralService.createEReferral(createEReferralRequestModel);
    if (_eReferralService.hasError) {
      error = _eReferralService.error!;
      setState(ViewState.ErrorLocal);
    } else {
      setState(ViewState.Idle);
    }
  }

  getEReferrals(SearchEReferralRequestModel searchEReferralRequestModel) async {
    setState(ViewState.BusyLocal);
    await _eReferralService.getEReferrals(searchEReferralRequestModel);
    if (_eReferralService.hasError) {
      error = _eReferralService.error!;
      setState(ViewState.ErrorLocal);
    } else {
      setState(ViewState.Idle);
    }
  }
}
