// ============================================================
// AuthUser — 认证域用户实体
// 纯 Dart 类，不依赖任何框架
// ============================================================

class AuthUser {
  final String id;
  final String? phone;
  final String? email;
  final String? nickname;
  final String? avatar;
  final String? kycStatus;
  final bool isActive;

  const AuthUser({
    required this.id,
    this.phone,
    this.email,
    this.nickname,
    this.avatar,
    this.kycStatus,
    this.isActive = true,
  });

  factory AuthUser.fromJson(Map<String, dynamic> json) {
    return AuthUser(
      id: json['id']?.toString() ?? '',
      phone: json['phone'] as String?,
      email: json['email'] as String?,
      nickname: json['nickname'] as String?,
      avatar: json['avatar'] as String?,
      kycStatus: json['kycStatus'] as String?,
      isActive: json['isActive'] as bool? ?? true,
    );
  }

  Map<String, dynamic> toJson() => {
        'id': id,
        if (phone != null) 'phone': phone,
        if (email != null) 'email': email,
        if (nickname != null) 'nickname': nickname,
        if (avatar != null) 'avatar': avatar,
        if (kycStatus != null) 'kycStatus': kycStatus,
        'isActive': isActive,
      };

  AuthUser copyWith({
    String? id,
    String? phone,
    String? email,
    String? nickname,
    String? avatar,
    String? kycStatus,
    bool? isActive,
  }) {
    return AuthUser(
      id: id ?? this.id,
      phone: phone ?? this.phone,
      email: email ?? this.email,
      nickname: nickname ?? this.nickname,
      avatar: avatar ?? this.avatar,
      kycStatus: kycStatus ?? this.kycStatus,
      isActive: isActive ?? this.isActive,
    );
  }

  @override
  bool operator ==(Object other) =>
      identical(this, other) || (other is AuthUser && other.id == id);

  @override
  int get hashCode => id.hashCode;

  @override
  String toString() => 'AuthUser(id=$id, phone=$phone, email=$email)';
}
