import 'package:diplomaticquarterapp/core/service/ancillary_orders_service.dart';
import 'package:diplomaticquarterapp/models/anicllary-orders/ancillary_order_list_model.dart';
import 'package:diplomaticquarterapp/models/anicllary-orders/ancillary_order_proc_model.dart';

import 'base_view_model.dart';
import '../../locator.dart';
import 'package:diplomaticquarterapp/core/enum/viewstate.dart';

class AnciallryOrdersViewModel extends BaseViewModel {
  bool hasError = false;

  AncillaryOrdersService _ancillaryService = locator<AncillaryOrdersService>();
  List<AncillaryOrdersListModel> get ancillaryLists =>
      _ancillaryService.ancillaryLists;

  List<AncillaryOrdersListProcListModel> get ancillaryListsDetails =>
      _ancillaryService.ancillaryProcLists;

  Future getOrders() async {
    hasError = false;
    setState(ViewState.Busy);
    await _ancillaryService.getOrders();
    if (_ancillaryService.hasError) {
      error = _ancillaryService.error;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }

  Future getOrdersDetails(appointmentNo, orderNo, projectID) async {
    hasError = false;
    setState(ViewState.Busy);
    await _ancillaryService.getOrdersDetails(appointmentNo, orderNo, projectID );
    if (_ancillaryService.hasError) {
      error = _ancillaryService.error;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }
}
