import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/service/sickleave_service.dart';
import 'package:doctor_app_flutter/core/service/medicine_service.dart';
import 'package:doctor_app_flutter/models/sickleave/add_sickleave_request.dart';
import 'package:doctor_app_flutter/models/sickleave/extend_sick_leave_request.dart';
import 'package:doctor_app_flutter/models/sickleave/get_all_sickleave_response.dart';

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

class SickLeaveViewModel extends BaseViewModel {
  SickLeaveService _sickLeaveService = locator<SickLeaveService>();
  get sickLeaveStatistics => _sickLeaveService.sickLeavestatisitics;
  get getAllSIckLeave => _sickLeaveService.getAllSickLeave;
  Future addSickLeave(AddSickLeaveRequest addSickLeaveRequest) async {
    setState(ViewState.Busy);
    await _sickLeaveService.addSickLeave(addSickLeaveRequest);
    if (_sickLeaveService.hasError) {
      error = _sickLeaveService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }

  Future extendSickLeave(GetAllSickLeaveResponse extendSickLeaveRequest) async {
    setState(ViewState.Busy);
    await _sickLeaveService.extendSickLeave(extendSickLeaveRequest);
    if (_sickLeaveService.hasError) {
      error = _sickLeaveService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }

  Future preSickLeaveStatistics(appoNo, patientMRN) async {
    setState(ViewState.Busy);
    await _sickLeaveService.getStatistics(appoNo, patientMRN);
    if (_sickLeaveService.hasError) {
      error = _sickLeaveService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }

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