/// Provider: Categories Provider
///
/// Manages the state of product categories using Riverpod.
library;

import 'package:riverpod_annotation/riverpod_annotation.dart';
import 'package:worker/features/products/domain/entities/category.dart';
import 'package:worker/features/products/domain/usecases/get_categories.dart';
import 'package:worker/features/products/presentation/providers/products_provider.dart';

part 'categories_provider.g.dart';

/// Categories Provider
///
/// Fetches and caches product categories.
/// Automatically handles loading, error, and data states.
///
/// Usage:
/// ```dart
/// final categoriesAsync = ref.watch(categoriesProvider);
///
/// categoriesAsync.when(
///   data: (categories) => CategoryFilterChips(categories: categories),
///   loading: () => ShimmerLoader(),
///   error: (error, stack) => ErrorWidget(error),
/// );
/// ```
@riverpod
Future<List<Category>> categories(Ref ref) async {
  // Get products repository with injected dependencies
  final repository = await ref.watch(productsRepositoryProvider.future);
  final useCase = GetCategories(repository);

  return await useCase();
}
