<?php

namespace Tests\Feature\Listeners;

use App\Enums\GuestNotificationType;
use App\Events\GuestPhotoUploaded;
use App\Models\Event;
use App\Models\Photo;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class SendPhotoUploadedNotificationTest extends TestCase
{
    use RefreshDatabase;

    public function test_photo_upload_event_creates_notification(): void
    {
        $event = Event::factory()->create(['status' => 'published']);
        $photo = Photo::factory()->for($event)->create(['guest_name' => 'Anne']);

        event(new GuestPhotoUploaded($event->refresh(), $photo->id, 'Anne', 'Anne'));

        $this->assertDatabaseHas('guest_notifications', [
            'event_id' => $event->id,
            'type' => GuestNotificationType::PHOTO_ACTIVITY->value,
        ]);
    }

    public function test_milestone_creates_achievement_notification(): void
    {
        config(['notifications.guest_achievements.milestones' => [5]]);

        $event = Event::factory()->create(['status' => 'published']);
        Photo::factory()->count(4)->for($event)->create(['guest_name' => 'Mia']);
        $photo = Photo::factory()->for($event)->create(['guest_name' => 'Mia']);

        event(new GuestPhotoUploaded($event->refresh(), $photo->id, 'Mia', 'Mia'));

        $this->assertDatabaseHas('guest_notifications', [
            'event_id' => $event->id,
            'type' => GuestNotificationType::ACHIEVEMENT_MAJOR->value,
        ]);
    }
}
