import 'package:boilerplate/data/repositories/categories_repository.dart';
import 'package:boilerplate/domain/entities/categories/categories_data.dart';
import 'package:dartz/dartz.dart';
import 'package:injectable/injectable.dart';

import '../../../core/utils/print_utils.dart';
import '../../../data/models/app/failure.dart';

@injectable
class GetCategoriesUseCase {
  final CategoriesRepository _categoriesRepo;

  GetCategoriesUseCase(this._categoriesRepo);

  Future<Either<List<CategoriesData>, Failure>> execute() async {
    try {
      final data = await _categoriesRepo.getCategories();

      return Left(data.result);
    } catch (err) {
      print('GetCategoriesUseCase Error : $err');
      return Right(Failure(
        errMessage: '$err',
      ));
    }
  }
}
