import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/HHC_get_all_services_request_modle.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/HHC_get_all_services_response_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/get_hhc_all_pres_orders_response_model.dart';
import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/HomeHealthCare/update_pres_oreder_request_model.dart';
import 'package:diplomaticquarterapp/core/service/AlHabibMedicalService/home_health_care_service.dart';
import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart';

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

class HomeHealthCareViewModel extends BaseViewModel {
  HomeHealthCareService _homeHealthCareService =
      locator<HomeHealthCareService>();

  List<HHCGetAllServicesResponseModel> get hhcAllServicesList =>
      _homeHealthCareService.hhcAllServicesList;
    List<GetHHCAllPresOrdersResponseModel> get hhcAllPresOrders =>
      _homeHealthCareService.hhcAllPresOrdersList;

  bool get isOrderUpdated =>
      _homeHealthCareService.isOrderUpdated;

  Future getHHCAllServices() async {
    HHCGetAllServicesRequestModel hHCGetAllServicesRequestModel =
        new HHCGetAllServicesRequestModel();
    setState(ViewState.Busy);
    await _homeHealthCareService
        .getHHCAllServices(hHCGetAllServicesRequestModel);
    if (_homeHealthCareService.hasError) {
      error = _homeHealthCareService.error;
      setState(ViewState.Error);
    } else {
      setState(ViewState.Idle);
    }
  }

  Future getHHCAllPresOrders() async {
    setState(ViewState.Busy);
    await _homeHealthCareService.getHHCAllPresOrders();
    if (_homeHealthCareService.hasError) {
      error = _homeHealthCareService.error;
      setState(ViewState.Error);
    } else {
      setState(ViewState.Idle);
    }
  }

  Future updateHHCPresOrder(UpdatePresOrderRequestModel updatePresOrderRequestModel) async {
    setState(ViewState.BusyLocal);
    await _homeHealthCareService.updateHHCPresOrder(updatePresOrderRequestModel);
    if (_homeHealthCareService.hasError) {
      error = _homeHealthCareService.error;
      setState(ViewState.ErrorLocal);
    } else {
      setState(ViewState.Idle);
    }
  }
}

/// Sample ordinal data type.
class ChartSeries {
  final String y;
  final int x;

  ChartSeries(this.y, this.x);
}
