import 'package:bloc/bloc.dart';
import 'package:equatable/equatable.dart';
import 'package:farm_tpf/custom_model/ActionType.dart';
import 'package:farm_tpf/data/api/app_exception.dart';
import 'package:farm_tpf/data/repository/repository.dart';
import 'package:farm_tpf/models/index.dart';

part 'plot_action_type_state.dart';

class PlotActionTypeCubit extends Cubit<PlotActionTypeState> {
  final Repository repository;
  PlotActionTypeCubit(this.repository) : super(PlotActionTypeInitial());

  Future<void> getAllActionTypes(int cropTypeId) async {
    try {
      emit(PlotActionTypeLoading());
      await repository.allActionTypes(cropTypeId, (data) {
        emit(PlotActionTypeSuccess(data));
      }, (error) {
        emit(PlotActionTypeError(AppException.handleError(error)));
      });
    } catch (e) {
      print(e);
      emit(PlotActionTypeError(AppException.handleError(e)));
    }
  }
}
