<?php

namespace Mtc\Plugins\BlockManager\Tests\Feature;

use Tests\TestCase;

class DesignTokenApiTest extends TestCase
{
    public function test_endpoint_returns_200_with_data_envelope(): void
    {
        $response = $this->getJson('/api/block-manager/tokens');
        $response->assertStatus(200);
        $response->assertJsonStructure(['data']);

        $data = $response->json('data');
        $this->assertIsArray($data);
        $this->assertNotEmpty($data, 'Token endpoint should return a non-empty list.');
    }

    public function test_endpoint_payload_entries_have_name_type_value(): void
    {
        $data = $this->getJson('/api/block-manager/tokens')->json('data');

        foreach ($data as $token) {
            foreach (['name', 'type', 'value'] as $key) {
                $this->assertArrayHasKey(
                    $key,
                    $token,
                    "Token endpoint entry missing '{$key}'."
                );
            }
        }
    }

    public function test_endpoint_includes_primary_color_and_gutter_width(): void
    {
        $data = $this->getJson('/api/block-manager/tokens')->json('data');
        $names = array_map(fn ($token) => $token['name'] ?? null, $data);

        $this->assertContains(
            '@primary_color',
            $names,
            'Endpoint must surface the @primary_color anchor token from variables.less.'
        );
        $this->assertContains(
            '@gutter_width',
            $names,
            'Endpoint must surface the @gutter_width anchor token from variables.less.'
        );
    }
}
