import 'package:boilerplate/data/repositories/product_repository.dart';
import 'package:boilerplate/domain/entities/product/product_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 GetProductDetailUseCase {
  final ProductRepository _productRepo;

  GetProductDetailUseCase(this._productRepo);

  Future<Either<ProductData, Failure>> execute(int productId) async {
    try {
      final data = await _productRepo.getProductDetail(productId);

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