/// États du BLoC Messagerie v4
library messaging_state;

import 'package:equatable/equatable.dart';

import '../../domain/entities/conversation.dart';
import '../../domain/entities/message.dart';

abstract class MessagingState extends Equatable {
  const MessagingState();

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

/// État initial
class MessagingInitial extends MessagingState {}

/// Chargement en cours
class MessagingLoading extends MessagingState {}

/// Liste des conversations chargée
class MesConversationsLoaded extends MessagingState {
  final List<ConversationSummary> conversations;

  const MesConversationsLoaded(this.conversations);

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

/// Conversation ouverte (détail avec messages)
class ConversationOuverte extends MessagingState {
  final Conversation conversation;

  const ConversationOuverte(this.conversation);

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

/// Messages d'une conversation chargés
class MessagesLoaded extends MessagingState {
  final String conversationId;
  final List<Message> messages;
  final bool hasMore;

  const MessagesLoaded({
    required this.conversationId,
    required this.messages,
    this.hasMore = false,
  });

  @override
  List<Object?> get props => [conversationId, messages, hasMore];
}

/// Message envoyé avec succès — la conversation s'actualise
class MessageEnvoye extends MessagingState {
  final Message message;
  final String conversationId;

  const MessageEnvoye({required this.message, required this.conversationId});

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

/// Conversation créée (après démarrage direct/rôle)
class ConversationCreee extends MessagingState {
  final Conversation conversation;

  const ConversationCreee(this.conversation);

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

/// Action silencieuse réussie (marquer lu, supprimer message, etc.)
class MessagingActionOk extends MessagingState {
  final String action;

  const MessagingActionOk(this.action);

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

/// Erreur
class MessagingError extends MessagingState {
  final String message;

  const MessagingError(this.message);

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