import 'package:flutter/material.dart';
import 'package:hmg_patient_app_new/services/error_handler_service.dart';
import 'monthly_reports_repo.dart';
class MonthlyReportsViewModel extends ChangeNotifier {
  final MonthlyReportsRepo monthlyReportsRepo;
  final ErrorHandlerService errorHandlerService;

  bool isLoading = false;

  MonthlyReportsViewModel({
    required this.monthlyReportsRepo,
    required this.errorHandlerService,
  });

  Future<bool> saveMonthlyReport({String? email}) async {
    isLoading = true;
    notifyListeners();

    final result = await monthlyReportsRepo.saveMonthlyReport(email: email);

    final success = result.fold(
          (failure) {
        errorHandlerService.handleError(failure: failure);
        return false;
      },
          (apiResponse) => (apiResponse.messageStatus ?? 0) == 1,
    );

    isLoading = false;
    notifyListeners();
    return success;
  }
}
