<?php

namespace Tests\Feature\Photobooth;

use App\Models\Event;
use App\Models\EventPhotoboothSetting;
use App\Models\Photo;
use App\Models\Tenant;
use App\Services\EventJoinTokenService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;

class PhotoboothFilterTest extends TestCase
{
    use RefreshDatabase;

    #[Test]
    public function gallery_api_returns_only_photobooth_photos_when_filter_is_active(): void
    {
        $tenant = Tenant::factory()->create();
        $event = Event::factory()
            ->for($tenant)
            ->create([
                'status' => 'published',
            ]);
        EventPhotoboothSetting::factory()
            ->for($event)
            ->create([
                'enabled' => true,
                'mode' => 'ftp',
            ]);

        Photo::factory()->create([
            'event_id' => $event->id,
            'ingest_source' => Photo::SOURCE_PHOTOBOOTH,
            'guest_name' => Photo::SOURCE_PHOTOBOOTH,
            'status' => 'approved',
        ]);

        Photo::factory()->create([
            'event_id' => $event->id,
            'ingest_source' => Photo::SOURCE_GUEST_PWA,
            'status' => 'approved',
        ]);

        /** @var EventJoinTokenService $tokens */
        $tokens = app(EventJoinTokenService::class);
        $token = $tokens->createToken($event, ['label' => 'Photobooth'])->getAttribute('plain_token');

        $response = $this->getJson("/api/v1/events/{$token}/photos?filter=photobooth");

        $response->assertOk();
        $this->assertCount(1, $response->json('data'));
        $this->assertSame(Photo::SOURCE_PHOTOBOOTH, $response->json('data.0.ingest_source'));
    }
}
