using Monitoring.Core.Domain.EventManagement;
using Monitoring.Core.Domain.ReportManagement;
using Monitoring.Core.Domain.RolePrimitives;
using Monitoring.Core.Domain.UserLogManagement;
using Monitoring.Core.Domain.UserPrimitives;

namespace Monitoring.Core.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 List<Member> Members { get; } = [];
	public List<Event> Events { get; } = [];
	public List<UserLog> Logs { get; } = [];

	public List<Report> Reports { get; } = [];
	public List<RefreshToken> RefreshTokens { get; } = [];

	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() { }
}
