<?php

declare(strict_types=1);

namespace Plugin\tnt_mcp\src\Mcp\OAuth\Repositories;

use League\OAuth2\Server\Entities\ScopeEntityInterface;

/** Shared helper: turn a list of league scope entities into a JSON array of identifiers. */
final class ScopeJson
{
    /**
     * @param list<ScopeEntityInterface> $scopes
     */
    public static function encode(array $scopes): string
    {
        $ids = [];
        foreach ($scopes as $scope) {
            $ids[] = $scope->getIdentifier();
        }

        return (string)json_encode($ids, \JSON_THROW_ON_ERROR);
    }
}
