using Knot.Shared.Kernel;
namespace Knot.Modules.Identity.Domain;
///
/// Сущность пользователя в контексте идентификации (Identity).
///
public sealed class User : AggregateRoot
{
public string Username { get; private set; }
public string PasswordHash { get; private set; }
public string DisplayName { get; private set; }
public string? Email { get; private set; }
public string? Bio { get; private set; }
public string? Avatar { get; private set; }
public DateTime? Birthday { get; private set; }
public DateTime CreatedAt { get; private set; }
public bool HideStoryViews { get; private set; }
private User(Guid id, string username, string passwordHash, string displayName, string? email, string? bio = null)
: base(id)
{
Username = username;
PasswordHash = passwordHash;
DisplayName = displayName;
Email = email;
Bio = bio;
CreatedAt = DateTime.UtcNow;
}
///
/// Фабричный метод для создания нового пользователя.
///
public static User Create(string username, string passwordHash, string displayName, string? email = null, string? bio = null)
{
return new User(Guid.NewGuid(), username, passwordHash, displayName, email, bio);
}
public void UpdateProfile(string displayName, string? bio, DateTime? birthday)
{
DisplayName = displayName;
Bio = bio;
Birthday = birthday;
}
public void UpdateAvatar(string? avatarUrl)
{
Avatar = avatarUrl;
}
public void UpdateSettings(bool hideStoryViews)
{
HideStoryViews = hideStoryViews;
}
public void ChangePassword(string newPasswordHash)
{
PasswordHash = newPasswordHash;
}
}