/// Use Case: Search Products
///
/// Business logic for searching products by query string.
library;

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

/// Search Products Use Case
///
/// Searches for products matching the given query string.
class SearchProducts {
  final ProductsRepository repository;

  const SearchProducts(this.repository);

  /// Execute the use case
  ///
  /// [query] - Search query string
  /// Returns list of products matching the query
  Future<List<Product>> call(String query) async {
    // Return all products if query is empty
    if (query.trim().isEmpty) {
      return await repository.getAllProducts();
    }

    return await repository.searchProducts(query);
  }
}
