<?php

declare(strict_types=1);

namespace App\Framework\Performance\Events;

use App\Framework\Core\ValueObjects\Timestamp;
use App\Framework\Performance\ValueObjects\PerformanceSnapshot;

/**
 * Event emitted when a performance-tracked operation fails
 */
final readonly class OperationFailedEvent
{
    public function __construct(
        public PerformanceSnapshot $snapshot,
        public \Throwable $exception,
        public Timestamp $timestamp
    ) {
    }

    /**
     * Get telemetry data for monitoring systems
     */
    public function toTelemetryData(): array
    {
        return array_merge(
            $this->snapshot->toTelemetryData(),
            [
                'event_type' => 'operation_failed',
                'status' => 'error',
                'error_type' => get_class($this->exception),
                'error_message' => $this->exception->getMessage(),
                'error_code' => $this->exception->getCode(),
            ]
        );
    }
}
