// 用户相关的操作状态 State 类，用于 RiverPod 中 Provider 的定义
import 'package:domain/entity/user_me_entity.dart';

class UserConfig {
  //用户的详情信息
  UserMeEntity? user;

  //用户的登录Token
  String? token;

  //用户姓名
  String? userName;

  //用户是否已经登录
  bool hasLogin = false;

  /// 获取用户默认的房产名称
  String? getDefaultEstateName() {
    return user?.estates
        ?.firstWhere(
          (estate) => estate.accounts?.any((a) => a.isDefault == 1) ?? false,
          orElse: () => UserMeEstates(), // 如果没有匹配项返回 null name
        )
        .name;
  }

  /// ===================================  插件自动生成-无需手动修改  ↓  ===================================

//<editor-fold desc="Data Methods">
  UserConfig({
    this.user,
    this.token,
    this.userName,
    required this.hasLogin,
  });

  UserConfig copyWith({
    UserMeEntity? user,
    String? token,
    String? userName,
    bool? hasLogin,
    String? registrationId,
    int? unreadNotificationsCount,
  }) {
    return UserConfig(
      user: user ?? this.user,
      token: token ?? this.token,
      userName: userName ?? this.userName,
      hasLogin: hasLogin ?? this.hasLogin,
    );
  }

//</editor-fold>
}
