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;
  List get allOffTime => _sickLeaveService.getOffTimeList;
  List get allReasons => _sickLeaveService.getReasons;
  List get coveringDoctors => _sickLeaveService.coveringDoctorsList;
  get getReschduleLeave => _sickLeaveService.getAllRescheduleLeave;
  get postSechedule => _sickLeaveService.postReschedule;
  get sickleaveResponse => _sickLeaveService.sickLeaveResponse;
  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(patientMRN) async {
    setState(ViewState.Busy);
    await _sickLeaveService.getSickLeave(patientMRN);
    if (_sickLeaveService.hasError) {
      error = _sickLeaveService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }

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

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

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

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

  Future addReschedule(request) async {
    setState(ViewState.Busy);
    await _sickLeaveService.addReschedule(request);

    if (_sickLeaveService.hasError) {
      error = _sickLeaveService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }

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