import 'package:doctor_app_flutter/core/enum/viewstate.dart';
import 'package:doctor_app_flutter/core/service/home/doctor_reply_service.dart';
import 'package:doctor_app_flutter/models/doctor/list_gt_my_patients_question_model.dart';
import 'package:doctor_app_flutter/models/doctor/replay/request_create_doctor_response.dart';

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

class DoctorReplayViewModel extends BaseViewModel {
  DoctorReplyService _doctorReplyService = locator<DoctorReplyService>();

  List<ListGtMyPatientsQuestions> get listDoctorWorkingHoursTable =>
      _doctorReplyService.listDoctorWorkingHoursTable;

  Future getDoctorReply() async {
    setState(ViewState.Busy);
    await getDoctorProfile();
    await _doctorReplyService.getDoctorReply();
    if (_doctorReplyService.hasError) {
      error = _doctorReplyService.error;
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }

  Future createDoctorResponse(
      String response, ListGtMyPatientsQuestions model) async {
    await getDoctorProfile();
    CreateDoctorResponseModel createDoctorResponseModel =
        CreateDoctorResponseModel(
          transactionNo: model.transactionNo.toString(),
          doctorResponse: response,
          infoStatus: 6,
          createdBy:this.doctorProfile.doctorID,
          infoEnteredBy: this.doctorProfile.doctorID,
          setupID:"010266"
        );
    setState(ViewState.BusyLocal);
    await _doctorReplyService.createDoctorResponse(createDoctorResponseModel);
    if (_doctorReplyService.hasError) {
      error = _doctorReplyService.error;
      setState(ViewState.ErrorLocal);
    } else {
      setState(ViewState.Idle);
      _doctorReplyService.getNotRepliedCount();

    }
  }
}
