<?php

declare(strict_types=1);

namespace App\Framework\Discovery\Processing;

use App\Framework\Core\ValueObjects\Byte;

/**
 * Processing result with statistics
 */
final readonly class ProcessingResult
{
    public function __construct(
        public int   $processedFiles,
        public int   $totalFiles,
        public int   $processedChunks,
        public int   $totalChunks,
        public float $processingTime,
        public Byte  $memoryUsed,
        public array $results
    ) {
    }

    public function isComplete(): bool
    {
        return $this->processedFiles === $this->totalFiles;
    }

    public function getSuccessRate(): float
    {
        return $this->totalFiles > 0 ? ($this->processedFiles / $this->totalFiles) : 0.0;
    }

    public function toArray(): array
    {
        return [
            'processed_files' => $this->processedFiles,
            'total_files' => $this->totalFiles,
            'processed_chunks' => $this->processedChunks,
            'total_chunks' => $this->totalChunks,
            'processing_time' => round($this->processingTime, 3),
            'memory_used' => $this->memoryUsed->toHumanReadable(),
            'success_rate' => round($this->getSuccessRate() * 100, 2) . '%',
            'is_complete' => $this->isComplete(),
        ];
    }
}
