/// Use Case: Get Products
///
/// Business logic for retrieving products with optional filtering.
library;

import 'package:worker/features/products/domain/entities/product.dart';
import 'package:worker/features/products/domain/repositories/products_repository.dart';

/// Get Products Use Case
///
/// Retrieves products from the repository with optional category filtering.
class GetProducts {
  final ProductsRepository repository;

  const GetProducts(this.repository);

  /// Execute the use case
  ///
  /// [categoryId] - Optional category ID to filter products
  /// [limitStart] - Starting index for pagination (default: 0)
  /// [limitPageLength] - Number of items per page (default: 12)
  /// Returns list of products (all or filtered by category)
  Future<List<Product>> call({
    String? categoryId,
    int limitStart = 0,
    int limitPageLength = 12,
  }) async {
    if (categoryId == null || categoryId == 'all') {
      return await repository.getAllProducts(
        limitStart: limitStart,
        limitPageLength: limitPageLength,
      );
    } else {
      return await repository.getProductsByCategory(
        categoryId,
        limitStart: limitStart,
        limitPageLength: limitPageLength,
      );
    }
  }
}
