import 'package:hmg_patient_app/core/enum/viewstate.dart';
import 'package:hmg_patient_app/core/service/medical/medical_service.dart';
import 'package:hmg_patient_app/core/viewModels/base_view_model.dart';
import 'package:hmg_patient_app/locator.dart';
import 'package:hmg_patient_app/models/Appointments/AppoimentAllHistoryResultList.dart';
import 'package:hmg_patient_app/models/Appointments/DoctorListResponse.dart';
import 'package:hmg_patient_app/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({bool isForTimeLine = false}) async {
    if (authenticatedUserObject.isLogin) {
      setState(ViewState.Busy);
      await _medicalService.getAppointmentHistory(isForTimeLine: isForTimeLine);
      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);
  }
//}
}
