import 'package:diplomaticquarterapp/uitl/app_toast.dart';

import '../../../core/enum/reportfilter_type.dart';
import '../../../core/enum/viewstate.dart';
import '../../../core/service/medical/reports_service.dart';
import '../../../locator.dart';
import '../base_view_model.dart';

class ReportsMonthlyViewModel extends BaseViewModel {
  ReportFilterType filterType = ReportFilterType.Requested;

  ReportsService _reportsService = locator<ReportsService>();

  String get userAgreementContent => _reportsService.userAgreementContent;
  bool get receiveHealthSummaryReport => _reportsService?.user?.receiveHealthSummaryReport ?? false;
  set receiveHealthSummaryReport(bool val) {
    _reportsService?.user?.receiveHealthSummaryReport = val;
  }

  getUserTermsAndConditions() async {
    setState(ViewState.Busy);
    await _reportsService.getUserTermsAndConditions();
    if (_reportsService.hasError) {
      error = _reportsService.error;
      setState(ViewState.Error);
    } else {
      setState(ViewState.Idle);
    }
  }

  updatePatientHealthSummaryReport({String message, bool isSummary, bool isUpdateEmail = false, String email}) async {
    setState(ViewState.BusyLocal);
    await _reportsService.updatePatientHealthSummaryReport(isSummary: isSummary);
    if (_reportsService.hasError) {
      error = _reportsService.error;
      AppToast.showErrorToast(message: error);
      setState(ViewState.ErrorLocal);
    } else {
      if (isUpdateEmail) {
        await _reportsService.updateEmail(email: email);
        if (_reportsService.hasError) {
          error = _reportsService.error;
          AppToast.showErrorToast(message: error);
          setState(ViewState.ErrorLocal);
        } else {
          AppToast.showSuccessToast(message: message);
          setState(ViewState.Idle);
        }
      } else {
        AppToast.showSuccessToast(message: message);
        setState(ViewState.Idle);
      }
    }
  }
}
