<?php

namespace App\Services\CreditScore;

class CreditScoreResult
{
    public function __construct(
        public readonly float $normalizedScore,
        public readonly int $creditScore,
        public readonly string $band,
        public readonly string $bandLabel,
        public readonly string $riskLevel,
        public readonly float $confidence,
        public readonly string $confidenceLevel,
        public readonly bool $thinFile,
        public readonly bool $manualReviewRequired,
        public readonly string $scoreVersion,
        public readonly array $components,
        public readonly array $overlays,
        public readonly string $explanation,
    ) {
    }

    public function toArray(): array
    {
        return [
            'normalized_score' => round($this->normalizedScore, 2),
            'credit_score' => $this->creditScore,
            'band' => $this->band,
            'band_label' => $this->bandLabel,
            'risk_level' => $this->riskLevel,
            'confidence' => round($this->confidence, 2),
            'confidence_level' => $this->confidenceLevel,
            'thin_file' => $this->thinFile,
            'manual_review_required' => $this->manualReviewRequired,
            'score_version' => $this->scoreVersion,
            'components' => collect($this->components)
                ->map(fn (ComponentResult $component): array => $component->toArray())
                ->all(),
            'overlays' => $this->overlays,
            'explanation' => $this->explanation,
        ];
    }
}
