<?php

declare(strict_types=1);

namespace Plugin\tnt_mcp\src\Mcp\OAuth;

use League\OAuth2\Server\Grant\AuthCodeGrant;

class CompressedAuthCodeGrant extends AuthCodeGrant
{
    protected function encrypt(string $unencryptedData): string
    {
        $compressed = \gzdeflate($unencryptedData, 9);
        return parent::encrypt($compressed);
    }

    protected function decrypt(string $encryptedData): string
    {
        $decrypted = parent::decrypt($encryptedData);
        $uncompressed = @\gzinflate($decrypted);
        return $uncompressed !== false ? $uncompressed : $decrypted;
    }
}
