// Freezed forwards factory parameter annotations to generated fields. // ignore_for_file: invalid_annotation_target import 'package:freezed_annotation/freezed_annotation.dart'; part 'profile_models.freezed.dart'; part 'profile_models.g.dart'; @freezed class UserProfile with _$UserProfile { const UserProfile._(); const factory UserProfile({ @JsonKey(fromJson: _idToString) required String id, @Default('') String username, @Default('') String nickname, @Default('') String signature, String? avatar, }) = _UserProfile; factory UserProfile.fromJson(Map json) => _$UserProfileFromJson(json); String get displayName => nickname.isNotEmpty ? nickname : username; } String _idToString(Object? value) => value?.toString() ?? ''; enum ProfileIssue { nicknameInvalid, signatureInvalid, avatarTooLarge, avatarUnsupported, } class ProfileInputException implements Exception { const ProfileInputException(this.issue); final ProfileIssue issue; } @freezed class ProfileState with _$ProfileState { const factory ProfileState({ UserProfile? profile, @Default(true) bool loading, @Default(false) bool saving, String? alert, ProfileIssue? issue, }) = _ProfileState; factory ProfileState.fromJson(Map json) => _$ProfileStateFromJson(json); }