/// Domain Entity: Member Card
///
/// Represents a member card with tier information, points, and QR code data.
/// This entity is used across the home feature to display membership information.
///
/// Tiers: Diamond, Platinum, Gold
///
/// This is a pure domain entity with no external dependencies.
library;

/// Member tier enum
enum MemberTier {
  /// Diamond tier - highest tier
  diamond,

  /// Platinum tier - middle tier
  platinum,

  /// Gold tier - entry tier
  gold;

  /// Get display name for tier
  String get displayName {
    switch (this) {
      case MemberTier.diamond:
        return 'DIAMOND';
      case MemberTier.platinum:
        return 'PLATINUM';
      case MemberTier.gold:
        return 'GOLD';
    }
  }
}

/// Member type enum
enum MemberType {
  /// Architect member type
  architect,

  /// Contractor member type
  contractor,

  /// Distributor member type
  distributor,

  /// Broker member type
  broker;

  /// Get display name for member type
  String get displayName {
    switch (this) {
      case MemberType.architect:
        return 'ARCHITECT MEMBERSHIP';
      case MemberType.contractor:
        return 'CONTRACTOR MEMBERSHIP';
      case MemberType.distributor:
        return 'DISTRIBUTOR MEMBERSHIP';
      case MemberType.broker:
        return 'BROKER MEMBERSHIP';
    }
  }
}

/// Member Card Entity
///
/// Contains all information needed to display a member card:
/// - Personal info (name, member ID)
/// - Membership details (tier, type, valid until)
/// - Loyalty points
/// - QR code data for scanning
class MemberCard {
  /// Unique member ID
  final String memberId;

  /// Member's full name
  final String name;

  /// Member type (Architect, Contractor, etc.)
  final MemberType memberType;

  /// Current membership tier
  final MemberTier tier;

  /// Current loyalty points balance
  final int points;

  /// Card expiration date
  final DateTime validUntil;

  /// QR code data (typically member ID or encoded data)
  final String qrData;

  /// Constructor
  const MemberCard({
    required this.memberId,
    required this.name,
    required this.memberType,
    required this.tier,
    required this.points,
    required this.validUntil,
    required this.qrData,
  });

  /// Check if card is expired
  bool get isExpired => DateTime.now().isAfter(validUntil);

  /// Check if card is expiring soon (within 30 days)
  bool get isExpiringSoon {
    final daysUntilExpiry = validUntil.difference(DateTime.now()).inDays;
    return daysUntilExpiry > 0 && daysUntilExpiry <= 30;
  }

  /// Copy with method for immutability
  MemberCard copyWith({
    String? memberId,
    String? name,
    MemberType? memberType,
    MemberTier? tier,
    int? points,
    DateTime? validUntil,
    String? qrData,
  }) {
    return MemberCard(
      memberId: memberId ?? this.memberId,
      name: name ?? this.name,
      memberType: memberType ?? this.memberType,
      tier: tier ?? this.tier,
      points: points ?? this.points,
      validUntil: validUntil ?? this.validUntil,
      qrData: qrData ?? this.qrData,
    );
  }

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

    return other is MemberCard &&
        other.memberId == memberId &&
        other.name == name &&
        other.memberType == memberType &&
        other.tier == tier &&
        other.points == points &&
        other.validUntil == validUntil &&
        other.qrData == qrData;
  }

  /// Hash code
  @override
  int get hashCode {
    return Object.hash(
      memberId,
      name,
      memberType,
      tier,
      points,
      validUntil,
      qrData,
    );
  }

  /// String representation
  @override
  String toString() {
    return 'MemberCard(memberId: $memberId, name: $name, memberType: $memberType, '
        'tier: $tier, points: $points, validUntil: $validUntil, qrData: $qrData)';
  }
}
