import 'package:equatable/equatable.dart';

/// User entity representing a user in the system
class UserEntity extends Equatable {
  final int id;
  final String firstName;
  final String name;
  final String? plateNumber;
  final String email;
  final String phone;
  final bool isParent;
  final String fullName;
  final String fullNameEmail;
  final String? referralCode;
  final String? avatar;
  final int departmentId;
  final bool isWareHouseUser;
  final int? wareHouseId;
  final int roleId;

  const UserEntity({
    required this.id,
    required this.firstName,
    required this.name,
    this.plateNumber,
    required this.email,
    required this.phone,
    this.isParent = false,
    required this.fullName,
    required this.fullNameEmail,
    this.referralCode,
    this.avatar,
    required this.departmentId,
    this.isWareHouseUser = false,
    this.wareHouseId,
    required this.roleId,
  });

  @override
  List<Object?> get props => [
        id,
        firstName,
        name,
        plateNumber,
        email,
        phone,
        isParent,
        fullName,
        fullNameEmail,
        referralCode,
        avatar,
        departmentId,
        isWareHouseUser,
        wareHouseId,
        roleId,
      ];

  /// Get display name
  String get displayName {
    if (fullName.isNotEmpty) return fullName;
    if (name.isNotEmpty) return name;
    return email;
  }

  /// Get initials from name (for avatar display)
  String get initials {
    if (firstName.isNotEmpty && name.isNotEmpty) {
      return (firstName.substring(0, 1) + name.substring(0, 1)).toUpperCase();
    }
    final parts = fullName.trim().split(' ');
    if (parts.isEmpty) return '?';
    if (parts.length == 1) {
      return parts[0].substring(0, 1).toUpperCase();
    }
    return (parts[0].substring(0, 1) + parts[parts.length - 1].substring(0, 1))
        .toUpperCase();
  }
}
