<?php

namespace Tests\Feature\Tenant;

use App\Models\Event;

class EventInviteQrCodeTest extends TenantTestCase
{
    public function test_join_token_response_includes_qr_code_data_url(): void
    {
        $event = Event::factory()
            ->for($this->tenant)
            ->create([
                'name' => ['de' => 'QR Einladungstest', 'en' => 'QR Invite Test'],
                'slug' => 'qr-invite-test',
            ]);

        $response = $this->authenticatedRequest('GET', "/api/v1/tenant/events/{$event->slug}/join-tokens");

        $response->assertOk();

        $data = $response->json('data');

        $this->assertIsArray($data);
        $this->assertNotEmpty($data, 'Expected at least one join token to be returned');

        $firstInvite = $data[0];

        $this->assertArrayHasKey('qr_code_data_url', $firstInvite);
        $this->assertNotNull($firstInvite['qr_code_data_url']);
        $this->assertIsString($firstInvite['qr_code_data_url']);
        $this->assertStringStartsWith('data:image/png;base64,', $firstInvite['qr_code_data_url']);
        $this->assertSame(url('/e/'.$firstInvite['token']), $firstInvite['url']);
    }
}
