using System.Security.Cryptography;

using Monitoring.Core.Domain.AssetManagement;
using Monitoring.Core.Domain.TokenManagement;

namespace Monitoring.Services;

public class TokenService
{
	public TokenCode GenerateToken()
	{
		using var rng = RandomNumberGenerator.Create();
		var byteArray = new byte[AssetDescription.MaxLength / 2];
		rng.GetBytes(byteArray);
		var token = Convert.ToBase64String(byteArray)
			.TrimEnd('=')
			.Replace('+', '-')
			.Replace('/', '_');
		return TokenCode.Create(token);
	}
}