import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/model/sick_leave/sick_leave.dart';
import 'package:diplomaticquarterapp/core/service/medical/PatientSickLeaveService.dart';
import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart';
import 'package:diplomaticquarterapp/locator.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';

class PatientSickLeaveViewMode extends BaseViewModel {
  PatientSickLeaveService _patientSickLeaveService =
      locator<PatientSickLeaveService>();

  List<SickLeave> get sickLeaveList => _patientSickLeaveService.sickLeaveList;

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

  Future sendSickLeaveEmail(
      {String message,
      int requestNo,
      String projectName,
      String doctorName,int projectID,String setupID}) async {
    setState(ViewState.Busy);
    await _patientSickLeaveService.sendSickLeaveEmail(
        requestNo: requestNo, projectName: projectName, doctorName: doctorName,projectID: projectID,setupID: setupID);
    if (_patientSickLeaveService.hasError) {
      error = _patientSickLeaveService.error;
      setState(ViewState.ErrorLocal);
      AppToast.showErrorToast(message: error);
    } else {
      AppToast.showSuccessToast(message: message);
      setState(ViewState.Idle);
    }
  }
}
