<?php

declare(strict_types=1);

namespace App\Framework\Discovery\Events;

use App\Framework\Core\ValueObjects\Duration;
use App\Framework\Core\ValueObjects\Timestamp;
use App\Framework\Discovery\ValueObjects\ScanType;
use App\Framework\Filesystem\ValueObjects\ScannerMetrics;

/**
 * Event fired when discovery process completes successfully
 */
final readonly class DiscoveryCompletedEvent
{
    public function __construct(
        public int $filesScanned,
        public Duration $duration,
        public ?ScannerMetrics $metrics,
        public ScanType $scanType,
        public Timestamp $timestamp
    ) {
    }

    public function toArray(): array
    {
        return [
            'files_scanned' => $this->filesScanned,
            'duration_seconds' => $this->duration->toSeconds(),
            'duration_human' => $this->duration->humanReadable(),
            'metrics' => $this->metrics?->toArray(),
            'scan_type' => $this->scanType->value,
            'timestamp' => $this->timestamp->toFloat(),
        ];
    }
}
