using System.Security.Cryptography;
using System.Text;

namespace Ikar.Server.Infrastructure.Auth;

public sealed class BotTokenService
{
    public string GenerateToken(Guid botId)
    {
        var secret = Convert.ToBase64String(RandomNumberGenerator.GetBytes(32))
            .TrimEnd('=')
            .Replace('+', '-')
            .Replace('/', '_');

        return $"ikarbot_{botId:N}_{secret}";
    }

    public string HashToken(string token)
    {
        var hashBytes = SHA256.HashData(Encoding.UTF8.GetBytes(token));
        return Convert.ToHexString(hashBytes);
    }
}
