using IdentityModule.Domain.RolePrimitives;
using IdentityModule.Domain.UserPrimitives;

using Monitoring.Core.Domain.EventManagement;
using Monitoring.Core.Domain.UserLogManagement;

namespace IdentityModule.Domain;

public class User
{
	public UserId Id { get; } = default!;
	public UserName Username { get; private set; } = default!;
	public UserUpperCaseName UpperCaseUsername { get; private set; } = default!;
	public PasswordHash PasswordHash { get; private set; } = default!;

	public RoleId RoleId { get; private set; } = default!;
	public Role Role { get; } = default!;

	public static User Create(UserId id, UserName username, PasswordHash passwordHash, RoleId roleId)
	{
		return new User(id, username, passwordHash, roleId);
	}

	public static User Create(UserName username, PasswordHash passwordHash, RoleId roleId)
	{
		return Create(new UserId(Guid.NewGuid()), username, passwordHash, roleId);
	}

	public void Update(UserName username, PasswordHash passwordHash, RoleId roleId)
	{
		Username = username;
		UpperCaseUsername = UserUpperCaseName.Create(username.Value);
		PasswordHash = passwordHash;
		RoleId = roleId;
	}

	private User(UserId id, UserName username, PasswordHash passwordHash, RoleId roleId)
	{
		Id = id;
		Username = username;
		UpperCaseUsername = UserUpperCaseName.Create(username.Value);
		PasswordHash = passwordHash;
		RoleId = roleId;
	}

	protected User() { }
}
