namespace Nocr.Users.AppServices.Users; public sealed class User { public long Id { get; set; } public string Username { get; private set; } = default!; public bool BotBlocked { get; private set; } private readonly List _identities = new(); public IReadOnlyCollection Identities => _identities; /// /// Used by ef. /// private User() { } private User(string username, params UserIdentity[] identities) { Username = username; // TODO: Check that there is no repeating identity types if (identities.GroupBy(x => x.Type).SelectMany(g => g.Skip(1)).Any()) { throw new InvalidOperationException($"All identities should be unique by {nameof(UserIdentity.Type)}"); } _identities.AddRange(identities); } public static User Initialize(string username, params UserIdentity[] identities) { if (string.IsNullOrWhiteSpace(username)) { throw new ArgumentNullException(nameof(username)); } if (username.Length is < 5 or > 32) { throw new ArgumentException("Username length should be between 5 and 32 symbols", username); } return new User(username, identities); } public void MarkAsBlocked() { BotBlocked = true; } public void MarkAsUnblocked() { BotBlocked = false; } }