import 'package:driverapp/core/enum/viewstate.dart';
import 'package:driverapp/core/model/orders/pending_orders_res_model.dart';
import 'package:driverapp/core/service/orders_service.dart';

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

class OrdersViewModel extends BaseViewModel {
  OrdersService _pendingOrdersService = locator<OrdersService>();

  List<PendingOrdersRes> get orders => _pendingOrdersService.orders;
  bool isBottomSheetAppear = false;

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

  Future insertOrder() async {
    setState(ViewState.ErrorLocal);
    await _pendingOrdersService.insertOrder();
    if (_pendingOrdersService.hasError) {
      error = _pendingOrdersService.error;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }

  showBottomSheet() {
    isBottomSheetAppear = true;
    setState(ViewState.Idle);
  }

  hideBottomSheet() {
    isBottomSheetAppear = false;
    setState(ViewState.Idle);
  }
}
