/// Domain Entity: Review Statistics
///
/// Aggregate statistics for product reviews.
library;

/// Review statistics entity
///
/// Contains aggregate data about reviews:
/// - Total number of feedbacks
/// - Average rating (0-5 scale)
class ReviewStatistics {
  const ReviewStatistics({
    required this.totalFeedback,
    required this.averageRating,
  });

  /// Total number of reviews/feedbacks
  final int totalFeedback;

  /// Average rating (0-5 scale)
  /// Note: This is already on 0-5 scale from API, no conversion needed
  final double averageRating;

  /// Check if there are any reviews
  bool get hasReviews => totalFeedback > 0;

  /// Get star rating rounded to nearest 0.5
  /// Used for displaying star icons
  double get displayRating {
    return (averageRating * 2).round() / 2;
  }

  @override
  bool operator ==(Object other) {
    if (identical(this, other)) return true;

    return other is ReviewStatistics &&
        other.totalFeedback == totalFeedback &&
        other.averageRating == averageRating;
  }

  @override
  int get hashCode => Object.hash(totalFeedback, averageRating);

  @override
  String toString() {
    return 'ReviewStatistics(totalFeedback: $totalFeedback, averageRating: $averageRating)';
  }
}
