using Nashel.BuildingBlocks.Domain; using Nashel.Modules.Identity.Domain.Enums; using Nashel.Modules.Identity.Domain.Events; namespace Nashel.Modules.Identity.Domain.Aggregates; public class Account : AggregateRoot { public string Phone { get; private set; } public string PasswordHash { get; private set; } public List Roles { get; private set; } = new(); public UserProfile Profile { get; private set; } = default!; // Конструктор для EF Core private Account() { } private Account(Guid id, string phone, string passwordHash) { Id = id; Phone = phone; PasswordHash = passwordHash; Roles.Add(Role.User); AddDomainEvent(new AccountCreatedEvent(Id)); } public static Account Create(string phone, string passwordHash) { return new Account(Guid.NewGuid(), phone, passwordHash); } public void SetProfile(UserProfile profile) { Profile = profile; } public void ChangePhone(string newPhone) { Phone = newPhone; } public void BecomePerformer() { if (!Roles.Contains(Role.Candidate) && !Roles.Contains(Role.Master)) { Roles.Add(Role.Candidate); } } public void PromoteToMaster() { if (Roles.Contains(Role.Candidate)) { Roles.Remove(Role.Candidate); } if (!Roles.Contains(Role.Master)) { Roles.Add(Role.Master); } } }