<?php

namespace Tests\Feature\Tenant;

use App\Models\Event;
use Carbon\Carbon;

class EventJoinTokenTtlPolicyTest extends TenantTestCase
{
    public function test_join_token_defaults_to_policy_ttl_when_expiry_missing(): void
    {
        Carbon::setTestNow(Carbon::parse('2026-01-05 12:00:00'));

        $event = Event::factory()
            ->for($this->tenant)
            ->create([
                'name' => ['de' => 'Token TTL Test', 'en' => 'Token TTL Test'],
                'slug' => 'token-ttl-test',
            ]);

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

        $response->assertCreated();

        $expectedExpiry = now()->addDays(7)->toIso8601String();

        $this->assertSame($expectedExpiry, $response->json('data.expires_at'));

        Carbon::setTestNow();
    }
}
