import 'package:equatable/equatable.dart';

/// Entité de domaine représentant un post social.
///
/// Cette entité est pure et indépendante de la couche de données.
/// Elle représente un post social dans le domaine métier.
class SocialPost extends Equatable {
  const SocialPost({
    required this.id,
    required this.content,
    required this.userId,
    required this.userFirstName,
    required this.userLastName,
    required this.userProfileImageUrl,
    required this.timestamp,
    this.imageUrl,
    this.likesCount = 0,
    this.commentsCount = 0,
    this.sharesCount = 0,
    this.isLikedByCurrentUser = false,
  });

  final String id;
  final String content;
  final String userId;
  final String userFirstName;
  final String userLastName;
  final String userProfileImageUrl;
  final DateTime timestamp;
  final String? imageUrl;
  final int likesCount;
  final int commentsCount;
  final int sharesCount;
  final bool isLikedByCurrentUser;

  /// Retourne le nom complet de l'auteur.
  String get authorFullName => '$userFirstName $userLastName';

  @override
  List<Object?> get props => [
        id,
        content,
        userId,
        userFirstName,
        userLastName,
        userProfileImageUrl,
        timestamp,
        imageUrl,
        likesCount,
        commentsCount,
        sharesCount,
        isLikedByCurrentUser,
      ];

  /// Crée une copie de ce post avec des valeurs modifiées.
  SocialPost copyWith({
    String? id,
    String? content,
    String? userId,
    String? userFirstName,
    String? userLastName,
    String? userProfileImageUrl,
    DateTime? timestamp,
    String? imageUrl,
    int? likesCount,
    int? commentsCount,
    int? sharesCount,
    bool? isLikedByCurrentUser,
  }) {
    return SocialPost(
      id: id ?? this.id,
      content: content ?? this.content,
      userId: userId ?? this.userId,
      userFirstName: userFirstName ?? this.userFirstName,
      userLastName: userLastName ?? this.userLastName,
      userProfileImageUrl: userProfileImageUrl ?? this.userProfileImageUrl,
      timestamp: timestamp ?? this.timestamp,
      imageUrl: imageUrl ?? this.imageUrl,
      likesCount: likesCount ?? this.likesCount,
      commentsCount: commentsCount ?? this.commentsCount,
      sharesCount: sharesCount ?? this.sharesCount,
      isLikedByCurrentUser: isLikedByCurrentUser ?? this.isLikedByCurrentUser,
    );
  }
}

