import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HealthCalculator/ClinicCategory.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HealthCalculator/DiseasesByClinic.dart';
import 'package:diplomaticquarterapp/core/service/AlHabibMedicalService/health-calculator/bariatrics-service.dart';
import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart';

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

class BariatricsViewModel extends BaseViewModel {
  BariatricsService _service = locator<BariatricsService>();

  List<ClinicCategory> get clinicCategoryList => _service.clinicCategoryList;

  List<DiseasesByClinic> get diseasesList => _service.diseasesList;

  void getClinicCategory() async {
    setState(ViewState.Busy);
    await _service.getClinicCategory();
    if (_service.hasError) {
      error = _service.error;
      setState(ViewState.Error);
    } else {
      getDiseaseByClinicId();
    }
  }

  void getDiseaseByClinicId() async {
    setState(ViewState.Busy);
    await _service.getDiseaseByClinicId();
    if (_service.hasError) {
      error = _service.error;
      setState(ViewState.Error);
    } else {
      setState(ViewState.Idle);
    }
  }

  Future searchDoctorsByTime(DiseasesByClinic disease) async {
    setState(ViewState.Busy);
    await _service.searchDoctorsByTime(disease);
    if (_service.hasError) {
      error = _service.error;
      setState(ViewState.ErrorLocal);
    } else {
      setState(ViewState.Idle);
    }
  }
}
