import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:krow_domain/krow_domain.dart';
import '../../../domain/usecases/get_tax_forms_usecase.dart';
import 'tax_forms_state.dart';

class TaxFormsCubit extends Cubit<TaxFormsState> {
  final GetTaxFormsUseCase _getTaxFormsUseCase;

  TaxFormsCubit(this._getTaxFormsUseCase) : super(const TaxFormsState());

  Future<void> loadTaxForms() async {
    emit(state.copyWith(status: TaxFormsStatus.loading));
    try {
      final List<TaxForm> forms = await _getTaxFormsUseCase();
      emit(state.copyWith(
        status: TaxFormsStatus.success,
        forms: forms,
      ));
    } catch (e) {
      emit(state.copyWith(
        status: TaxFormsStatus.failure,
        errorMessage: e.toString(),
      ));
    }
  }
}
