<?php

namespace Tests\Tenant;

use App\Http\Controllers\NotificationMapController;
use App\Models\NotificationMap;
use App\NotificationMaps\NotificationPayloadMapper;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Tests\TenantTestCase;

class NotificationMapDocsTest extends TenantTestCase
{
    private function controller(): NotificationMapController
    {
        return new NotificationMapController(new NotificationPayloadMapper());
    }

    public function testDocsReturnsOpenApiForMap(): void
    {
        NotificationMap::create([
            'name' => 'Partner Feed',
            'type' => 'vehicle',
            'active' => true,
            'field_map' => [['source' => 'stock_id', 'destination' => 'uuid', 'type' => 'string']],
            'validation' => ['uuid' => ['required', 'string']],
        ]);

        $response = $this->controller()->docs('partner-feed');
        $doc = $response->getData(true);

        $this->assertSame('3.0.0', $doc['openapi']);
        $this->assertArrayHasKey('/api/notifications/{tenant}/partner-feed', $doc['paths']);
    }

    public function testDocsAvailableForInactiveMap(): void
    {
        NotificationMap::create(['name' => 'Dormant', 'type' => 'vehicle', 'active' => false]);

        $response = $this->controller()->docs('dormant');

        $this->assertSame(200, $response->getStatusCode());
    }

    public function testDocsUnknownSlugReturns404(): void
    {
        $this->expectException(NotFoundHttpException::class);

        $this->controller()->docs('does-not-exist');
    }
}
