import 'package:bloc/bloc.dart';
import 'package:dio/dio.dart';
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:hoshan/data/model/tools_categories_model.dart';
import 'package:hoshan/data/repository/bot_repository.dart';

part 'category_state.dart';

class CategoryCubit extends Cubit<CategoryState> {
  CategoryCubit() : super(CategoryInitial());

  void getAllCategorie() async {
    emit(CategoryLoading());
    try {
      final response = await BotRepository.getAllCategories();
      if (response.categories == null || response.categories!.isEmpty) {
        emit(CategoryEmpty());
      } else {
        emit(CategorySuccess(categories: response.categories!));
      }
    } on DioException catch (e) {
      emit(CategoryFail());
      if (kDebugMode) {
        print("Dio Error is : $e");
      }
    }
  }
}
