using Modules.User.Domain.Gateways;

namespace Modules.User.Domain.Entities.User;

public class User
{
    public Guid Id { get; private set; }

    public Account.Account Account { get; private set; } = default!;

    public string NickName { get; private set; } = default!;

    public string? FirstName { get; private set; }
    public string? Patronymic { get; private set; }
    public string? LastName { get; private set; }
    public DateOnly? BirthDate { get; set; }

    public string? AvatarId { get; private set; }
    public Guid? LanguageId { get; private set; }

    private User() { }

    public User(Models.User model)
    {
        Id = model.Id;
        Account = new Account.Account(model.Account);
        NickName = model.NickName;
        FirstName = model.FirstName;
        Patronymic = model.Patronymic;
        LastName = model.LastName;
        BirthDate = model.BirthDate;
        AvatarId = model.AvatarId;
        LanguageId = model.LanguageId;
    }

    public static User Create(string email, string password, IPasswordGateway passwordHasher, string nickname)
    {
        if (string.IsNullOrWhiteSpace(nickname)) throw new ArgumentNullException(nameof(nickname));
        return new User
        {
            Account = Entities.Account.Account.Create(email, password, passwordHasher),
            NickName = nickname,
        };
    }

    public void SetAvatar(string? avatarId)
    {
        AvatarId = avatarId;
    }

    public void SetFirstName(string? value)
    {
        FirstName = value;
    }

    public void SetPatronymic(string? value)
    {
        Patronymic = value;
    }

    public void SetLastName(string? value)
    {
        LastName = value;
    }

    public void SetBirthDate(DateOnly? value)
    {
        BirthDate = value;
    }

    public void SetLanguageId(Guid? value)
    {
        LanguageId = value;
    }
}