<?php

namespace Tests\Unit;

use App\Models\User;
use App\Services\ApplicationUrlService;
use App\Services\Docs\ApiDocsService;
use PHPUnit\Framework\TestCase;

class ApiDocsServiceTest extends TestCase
{
    private function docsService(): ApiDocsService
    {
        $urls = $this->createMock(ApplicationUrlService::class);
        $urls->method('docsSwaggerMergedJsonUrl')->with(false)->willReturn('/api/documentation/swagger.json');

        return new ApiDocsService($urls);
    }

    public function test_public_bootstrap_matches_ci_public_flags(): void
    {
        $svc = $this->docsService();
        $b = $svc->bootstrap(null, true);

        $this->assertFalse($b['try_it_out_enabled']);
        $this->assertFalse($b['persist_authorization']);
        $this->assertFalse($b['show_authorize_button']);
        $this->assertSame('public', $b['variant']);
        $this->assertNull($b['welcome_name']);
    }

    public function test_full_bootstrap_enables_try_and_welcome(): void
    {
        $user = new User([
            'firstname' => 'A',
            'lastname' => 'B',
            'email' => 'x@y.z',
        ]);
        $svc = $this->docsService();
        $b = $svc->bootstrap($user, false);

        $this->assertTrue($b['try_it_out_enabled']);
        $this->assertTrue($b['persist_authorization']);
        $this->assertTrue($b['show_authorize_button']);
        $this->assertSame('full', $b['variant']);
        $this->assertSame('A B', $b['welcome_name']);
    }
}
