// 用户设置数据模型 — 手写不可变类(避免 build_runner 依赖) /// 主题模式 — 与系统设置同步 enum ThemeMode { light, dark, system } /// 默认画笔类型(复用 StrokeModel 中的枚举值) enum DefaultBrushType { pen('pen'), pencil('pencil'), marker('marker'); const DefaultBrushType(this.value); final String value; } /// 用户设置 — 持久化的个人偏好 /// /// 存储用户的主题偏好、默认画笔、字体大小等。 /// 每个用户只有一条设置记录,通过 [userId] 关联。 class UserSettings { final String id; final String userId; final ThemeMode theme; final DefaultBrushType defaultBrushType; final String defaultBrushColor; final double fontSize; final DateTime createdAt; final DateTime updatedAt; const UserSettings({ required this.id, required this.userId, this.theme = ThemeMode.system, this.defaultBrushType = DefaultBrushType.pen, this.defaultBrushColor = '#2D2420', this.fontSize = 16.0, required this.createdAt, required this.updatedAt, }); UserSettings copyWith({ String? id, String? userId, ThemeMode? theme, DefaultBrushType? defaultBrushType, String? defaultBrushColor, double? fontSize, DateTime? createdAt, DateTime? updatedAt, }) => UserSettings( id: id ?? this.id, userId: userId ?? this.userId, theme: theme ?? this.theme, defaultBrushType: defaultBrushType ?? this.defaultBrushType, defaultBrushColor: defaultBrushColor ?? this.defaultBrushColor, fontSize: fontSize ?? this.fontSize, createdAt: createdAt ?? this.createdAt, updatedAt: updatedAt ?? this.updatedAt, ); Map toJson() => { 'id': id, 'user_id': userId, 'theme': theme.name, 'default_brush_type': defaultBrushType.value, 'default_brush_color': defaultBrushColor, 'font_size': fontSize, 'created_at': createdAt.toIso8601String(), 'updated_at': updatedAt.toIso8601String(), }; factory UserSettings.fromJson(Map json) => UserSettings( id: json['id'] as String, userId: json['user_id'] as String, theme: ThemeMode.values.firstWhere( (t) => t.name == json['theme'], orElse: () => ThemeMode.system, ), defaultBrushType: DefaultBrushType.values.firstWhere( (b) => b.value == json['default_brush_type'], orElse: () => DefaultBrushType.pen, ), defaultBrushColor: (json['default_brush_color'] as String?) ?? '#2D2420', fontSize: (json['font_size'] as num?)?.toDouble() ?? 16.0, createdAt: DateTime.parse(json['created_at'] as String), updatedAt: DateTime.parse(json['updated_at'] as String), ); /// 创建默认设置的工厂方法 factory UserSettings.create({ required String userId, ThemeMode theme = ThemeMode.system, }) { final now = DateTime.now(); return UserSettings( id: userId, userId: userId, theme: theme, createdAt: now, updatedAt: now, ); } }