import 'package:diplomaticquarterapp/core/enum/viewstate.dart';
import 'package:diplomaticquarterapp/core/service/medical/medical_service.dart';
import 'package:diplomaticquarterapp/core/viewModels/base_view_model.dart';
import 'package:diplomaticquarterapp/locator.dart';
import 'package:diplomaticquarterapp/models/Appointments/AppoimentAllHistoryResultList.dart';
import 'package:diplomaticquarterapp/models/Appointments/DoctorListResponse.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/models/DoctorScheduleResponse.dart';

class MedicalViewModel extends BaseViewModel {
  MedicalService _medicalService = locator<MedicalService>();

  List<AppoitmentAllHistoryResultList> get appoitmentAllHistoryResultList => _medicalService.appoitmentAllHistoryResultList;
  List<DoctorScheduleResponse> get getDoctorScheduleList => _medicalService.doctorScheduleResponse;
  List<String> get freeSlots => _medicalService.freeSlots;
  getAppointmentHistory() async {
    if (authenticatedUserObject.isLogin) {
      setState(ViewState.Busy);
      await _medicalService.getAppointmentHistory();
      if (_medicalService.hasError) {
        error = _medicalService.error;
        setState(ViewState.Error);
      } else
        setState(ViewState.Idle);
    }
  }

  getDoctorSchedule(DoctorList doctorRequest) async {
    //if (authenticatedUserObject.isLogin) {
    setState(ViewState.Busy);
    await _medicalService.getSchedule(doctorRequest);
    if (_medicalService.hasError) {
      error = _medicalService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
    //}
  }

  getFreeSlots(DoctorList doctorRequest) async {
    //if (authenticatedUserObject.isLogin) {
    setState(ViewState.Busy);
    await _medicalService.getFreeSlot(doctorRequest);
    if (_medicalService.hasError) {
      error = _medicalService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }
  //}
}
