<?php

declare(strict_types=1);

final class ReminderScorer
{
    /**
     * @var array<object>
     */
    private array $scores = [];

    public function __construct()
    {
        $this->scores = [
            new DeadlineScore(),
            new StageScore(),
            new InactivityScore(),
            new ReminderFatigueScore(),
            // بعداً:
            // new AIRiskScore(),
        ];
    }

    /**
     * محاسبه امتیاز نهایی
     */
    public function score(array $row): ReminderDecision
    {
        $decision = new ReminderDecision();

        foreach ($this->scores as $scoreEngine) {

            $result = $scoreEngine->calculate($row);

            if (!empty($result['reasons'])) {

                foreach ($result['reasons'] as $reason) {

                    $decision->addScoreReason(
                        $result['name'],
                        $reason
                    );

                }

            }

            $decision->addScore(
                $result['name'],
                $result['score']
            );

            if (!empty($result['reason'])) {

                $decision->addScoreReason(
                    $result['name'],
                    $result['reason']
                );

                $decision->addReason(
                    $result['reason']
                );
            }
        }
        

        return $decision;
    }

    /**
     * افزودن Score جدید بدون تغییر کلاس
     */
    public function add(object $score): void
    {
        $this->scores[] = $score;
    }
}