using Monitoring.Core.Domain.OrganizationManagement;

namespace Monitoring.Core.Domain.TokenManagement;

/// <summary>
/// Токен доступа к API
/// </summary>
public class Token
{
	/// <summary>
	/// ИД
	/// </summary>
	public TokenId Id { get; } = default!;

	/// <summary>
	/// Название токена
	/// </summary>
	public TokenName Name { get; private set; } = default!;

	/// <summary>
	/// Код
	/// </summary>
	public TokenCode Code { get; private set; } = default!;

	/// <summary>
	/// ИД организации, в которой существует токен.
	/// </summary>
	public OrganizationId OrganizationId { get; } = default!;

	/// <summary>
	/// Организация, в которой существует токен.
	/// </summary>
	public Organization Organization { get; } = default!;

	public static Token Create(OrganizationId organizationId, TokenName name, TokenCode code)
	{
		return new Token(organizationId, name, code);
	}

	public void Update(TokenName name)
	{
		Name = name;
	}

	public void NewCode(TokenCode code)
	{
		Code = code;
	}

	private Token(OrganizationId organizationId, TokenName name, TokenCode code)
	{
		Id = new(Guid.NewGuid());
		Name = name;
		OrganizationId = organizationId;
		Code = code;
	}

	// For EF Core
	protected Token() { }
}