class KRAuthMethod {
  final String authIdentifier;
  final String authType;
  final bool verified;

  KRAuthMethod({
    required this.authIdentifier,
    required this.authType,
    required this.verified,
  });

  factory KRAuthMethod.fromJson(Map<String, dynamic> json) {
    return KRAuthMethod(
      authIdentifier: json['auth_identifier'] ?? '',
      authType: json['auth_type'] ?? '',
      verified: json['verified'] ?? false,
    );
  }
}

class KRUserInfo {
  final int id;
  final String email;
  final int refererId;
  final String referCode;
  final String avatar;
  final String areaCode;
  final String telephone;
  final int balance;
  final int commission;
  final int referralPercentage;
  final bool onlyFirstPurchase;
  final int giftAmount;
  final String shareUrl;

  // 新增 auth_methods 列表
  final List<KRAuthMethod> authMethods;

  KRUserInfo({
    required this.id,
    required this.email,
    this.refererId = 0,
    this.referCode = '',
    this.avatar = '',
    this.areaCode = '',
    this.telephone = '',
    this.balance = 0,
    this.commission = 0,
    this.referralPercentage = 0,
    this.onlyFirstPurchase = false,
    this.giftAmount = 0,
    this.shareUrl = '',
    this.authMethods = const [],
  });

  factory KRUserInfo.fromJson(Map<String, dynamic> json) {
    return KRUserInfo(
      id: json['id'] ?? 0,
      email: json['email'] ?? '',
      refererId: json['referer_id'] ?? 0,
      referCode: json['refer_code'] ?? '',
      avatar: json['avatar'] ?? '',
      areaCode: json['area_code'] ?? '',
      telephone: json['telephone'] ?? '',
      balance: json['balance'] ?? 0,
      commission: json['commission'] ?? 0,
      referralPercentage: json['referral_percentage'] ?? 0,
      onlyFirstPurchase: json['only_first_purchase'] ?? false,
      giftAmount: json['gift_amount'] ?? 0,
      shareUrl: json['share_link'] ?? '',
      authMethods: (json['auth_methods'] as List<dynamic>?)
          ?.map((e) => KRAuthMethod.fromJson(e))
          .toList() ??
          [],
    );
  }
}
