#!/usr/bin/env php
<?php

declare(strict_types=1);

use ShipBG\WooCommerce\API\Client;

if (! defined('ABSPATH')) {
    define('ABSPATH', dirname(__DIR__).'/');
}

require dirname(__DIR__).'/vendor/autoload.php';

$reflection = new ReflectionClass(Client::class);

$declaration = static function (string $constant) use ($reflection): array {
    $value = $reflection->getReflectionConstant($constant)?->getValue();

    if (! is_string($value)) {
        throw new RuntimeException("Missing Client::{$constant} capability declaration.");
    }

    $values = array_values(array_filter(array_map('trim', explode(',', $value))));
    sort($values);

    return $values;
};

echo json_encode([
    'contracts' => $declaration('SUPPORTED_CONTRACTS'),
    'features' => $declaration('SUPPORTED_FEATURES'),
], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR).PHP_EOL;
