import 'package:doctor_app_flutter/core/enum/view_state.dart';
import 'package:doctor_app_flutter/core/model/insurance/insurance_approval.dart';
import 'package:doctor_app_flutter/core/model/insurance/insurance_approval_in_patient_model.dart';
import 'package:doctor_app_flutter/core/service/patient_medical_file/insurance/InsuranceCardService.dart';
import 'package:doctor_app_flutter/core/viewModel/base_view_model.dart';
import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart';

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

class InsuranceViewModel extends BaseViewModel {
  InsuranceCardService _insuranceCardService = locator<InsuranceCardService>();

  List<InsuranceApprovalModel> get insuranceApproval =>
      _insuranceCardService.insuranceApproval;

  List<InsuranceApprovalInPatientModel> get insuranceApprovalInPatient =>
      _insuranceCardService.insuranceApprovalInPatient;

  Future getInsuranceApproval(PatiantInformtion patient,
      {int? appointmentNo, int? projectId}) async {
    error = "";
    setState(ViewState.Busy);
    if (appointmentNo != null)
      await _insuranceCardService.getInsuranceApproval(patient,
          appointmentNo: appointmentNo, projectId: projectId);
    else
      await _insuranceCardService.getInsuranceApproval(patient);
    if (_insuranceCardService.hasError) {
      error = "No Insurance Approval Found";
      setState(ViewState.Error);
    } else
      setState(ViewState.Idle);
  }

  Future getInsuranceInPatient({required int mrn}) async {
    //hasError = false;
    //_insuranceCardService.clearInsuranceCard();
    setState(ViewState.Busy);
    await _insuranceCardService.getInsuranceApprovalInPatient(mrn: mrn);
    if (_insuranceCardService.hasError) {
      error = _insuranceCardService.error;
      setState(ViewState.ErrorLocal);
    } else
      setState(ViewState.Idle);
  }
}
