import 'package:equatable/equatable.dart';
import '../../domain/entities/feed_item.dart';

abstract class UnifiedFeedState extends Equatable {
  const UnifiedFeedState();
  
  @override
  List<Object?> get props => [];
}

class UnifiedFeedInitial extends UnifiedFeedState {}

class UnifiedFeedLoading extends UnifiedFeedState {}

class UnifiedFeedLoaded extends UnifiedFeedState {
  final List<FeedItem> items;
  final bool hasReachedMax;
  final bool isFetchingMore;
  /// Message d'erreur affiché une fois (ex. « Impossible de charger plus »), à consommer puis effacer par l'UI.
  final String? loadMoreErrorMessage;

  const UnifiedFeedLoaded({
    required this.items,
    this.hasReachedMax = false,
    this.isFetchingMore = false,
    this.loadMoreErrorMessage,
  });

  UnifiedFeedLoaded copyWith({
    List<FeedItem>? items,
    bool? hasReachedMax,
    bool? isFetchingMore,
    String? loadMoreErrorMessage,
  }) {
    return UnifiedFeedLoaded(
      items: items ?? this.items,
      hasReachedMax: hasReachedMax ?? this.hasReachedMax,
      isFetchingMore: isFetchingMore ?? false,
      loadMoreErrorMessage: loadMoreErrorMessage,
    );
  }

  @override
  List<Object?> get props => [items, hasReachedMax, isFetchingMore, loadMoreErrorMessage];
}

class UnifiedFeedError extends UnifiedFeedState {
  final String message;

  const UnifiedFeedError(this.message);

  @override
  List<Object?> get props => [message];
}
