<?php

declare(strict_types=1);

namespace App\Framework\Database\Profiling\Events;

use App\Framework\Database\Profiling\QueryProfile;
use App\Framework\Database\Profiling\SlowQueryAlert;

/**
 * Event dispatched when a slow query is detected
 */
final readonly class SlowQueryDetectedEvent
{
    public function __construct(
        public SlowQueryAlert $alert,
        public QueryProfile $profile
    ) {
    }

    /**
     * Get event name for identification
     */
    public function getEventName(): string
    {
        return 'database.slow_query_detected';
    }

    /**
     * Convert to array for logging/serialization
     */
    public function toArray(): array
    {
        return [
            'event' => $this->getEventName(),
            'alert' => $this->alert->toArray(),
            'profile_id' => $this->profile->id,
        ];
    }
}
