import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/features/monthly_reports/terms_conditions_repo.dart';
import 'package:hmg_patient_app_new/services/error_handler_service.dart';

class TermsConditionsViewModel extends ChangeNotifier {
  final TermsConditionsRepo termsConditionsRepo;
  final ErrorHandlerService errorHandlerService;

  String? termsConditionsHtml;
  bool isLoading = false;

  TermsConditionsViewModel({
    required this.termsConditionsRepo,
    required this.errorHandlerService,
  });

  Future<void> getTermsConditions({
    Function()? onSuccess,
    Function(String)? onError,
  }) async {
    isLoading = true;
    notifyListeners();

    final result = await termsConditionsRepo.getTermsConditions();

    result.fold(
          (failure) async {
        await errorHandlerService.handleError(failure: failure);
        isLoading = false;
        notifyListeners();
        if (onError != null) {
          onError(failure.message ?? 'Something went wrong');
        }
      },
          (html) {
        termsConditionsHtml = html;
        isLoading = false;
        notifyListeners();
        if (onSuccess != null) onSuccess();
      },
    );
  }
}


