import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/childvaccines/List_BabyInformationModel.dart';
import 'package:diplomaticquarterapp/core/model/childvaccines/delete_baby_model.dart';
//========
import 'package:diplomaticquarterapp/core/service/childvaccines/add_new_child_service.dart';
import 'package:diplomaticquarterapp/core/service/childvaccines/child_vaccines_service.dart';
import 'package:diplomaticquarterapp/core/service/childvaccines/delete_baby_service.dart';

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

class ChildVaccinesViewModel extends BaseViewModel{
  ChildVaccinesService _childVaccinesService = locator<ChildVaccinesService>();

  List<List_BabyInformationModel> get  babyInformationModelList=> _childVaccinesService.babyInformationModelList;


//===========
  CreteNewBabyService _creteNewBabyService = locator<CreteNewBabyService>();

  DeleteBabyService _deleteBabyService = locator<DeleteBabyService>();
  bool isAdded = false;
  bool isDeleted = false;
  //============


  getNewUserOrders() async {
    setState(ViewState.Busy);
    await _childVaccinesService.getNewUserOrders();
    if (_childVaccinesService.hasError) {
      error = _childVaccinesService.error;
      setState(ViewState.Error);
    } else
      getBabyInformatioRequestOrders();
  }

  getBabyInformatioRequestOrders() async {
    await _childVaccinesService.getAllBabyInformationOrders();
    if (_childVaccinesService.hasError) {
      error = _childVaccinesService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }



  ///delete baby
  deleteBabyOrders({ DeleteBaby newChild}) async {
    setState(ViewState.Busy);
    //await _creteNewBabyService.getCreateNewBabyOrders(newChild: newChild, userID: _childVaccinesService.userID);
    await _deleteBabyService.getDeleteBabyOrder(deleteChild: newChild,babyID: newChild.babyID);
    //getDeleteBabyOrder(deleteChild: newChild,);
    // getDeleteBabyOrder
    if (_creteNewBabyService.hasError) {
      error = _creteNewBabyService.error;
      setState(ViewState.Error);
    } else {
      isDeleted = true;
      setState(ViewState.Idle);
      await _childVaccinesService.getAllBabyInformationOrders();
      if (_childVaccinesService.hasError) {
        error = _childVaccinesService.error;
        setState(ViewState.Error);
      } else{

      }
    }
  }

}