import 'package:doctor_app_flutter/core/enum/view_state.dart';
import 'package:doctor_app_flutter/core/model/dashboard/doctor_schedule.dart';
import 'package:doctor_app_flutter/core/service/home/schedule_service.dart';
import 'package:doctor_app_flutter/core/model/doctor/list_doctor_working_hours_table_model.dart';

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

class ScheduleViewModel extends BaseViewModel {
  ScheduleService _scheduleService = locator<ScheduleService>();

  List<ListDoctorWorkingHoursTable> get listDoctorWorkingHoursTable =>
      _scheduleService.listDoctorWorkingHoursTable;

  List<DoctorSchedule> get getDoctorRotation =>
      _scheduleService.doctorRotation;
  Future getDoctorSchedule() async {
    setState(ViewState.Busy);
    await _scheduleService.getDoctorSchedule();
    if (_scheduleService.hasError) {
      error = _scheduleService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }

  Future getDoctorRota(String fromDate, String toDate,{int pageNo=1}) async {
    setState(ViewState.Busy);
    await _scheduleService.getDoctorRota(fromDate,toDate,pageNo:pageNo);
    if (_scheduleService.hasError) {
      error = _scheduleService.error;
      setState(ViewState.ErrorLocal);
    } else {
      setState(ViewState.Idle);
    }
  }
}
