<?php

namespace Tests\Feature\Api\Tenant;

use App\Models\Event;
use App\Models\EventPackage;
use App\Models\EventPackageAddon;
use App\Models\Package;
use Tests\Feature\Tenant\TenantTestCase;

class EventAddonsSummaryTest extends TenantTestCase
{
    public function test_event_resource_includes_addons(): void
    {
        $package = Package::factory()->endcustomer()->create([
            'max_guests' => 50,
            'max_photos' => 100,
        ]);

        $event = Event::factory()->for($this->tenant)->create([
            'status' => 'published',
        ]);

        $eventPackage = EventPackage::create([
            'event_id' => $event->id,
            'package_id' => $package->id,
            'purchased_price' => $package->price,
            'purchased_at' => now(),
            'used_photos' => 0,
            'used_guests' => 0,
            'gallery_expires_at' => now()->addDays(30),
            'extra_guests' => 20,
        ]);

        EventPackageAddon::create([
            'event_package_id' => $eventPackage->id,
            'event_id' => $event->id,
            'tenant_id' => $this->tenant->id,
            'addon_key' => 'extra_guests_100',
            'quantity' => 1,
            'extra_guests' => 100,
            'status' => 'completed',
            'purchased_at' => now(),
        ]);

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

        $response->assertOk();
        $response->assertJsonPath('data.addons.0.key', 'extra_guests_100');
        $response->assertJsonPath('data.addons.0.extra_guests', 100);
    }
}
