<?php

namespace App\Services\Promotions\Placement;

use RuntimeException;

class ScoreBandClassifier
{
    public function fromScore(?float $score, bool $allowNull = false): ?string
    {
        if ($score === null) {
            return $allowNull ? null : 'D';
        }
        if ($score >= 90.0 && $score <= 100.0) {
            return 'A';
        }
        if ($score >= 80.0) {
            return 'B';
        }
        if ($score >= 70.0) {
            return 'C';
        }
        if ($score >= 60.0) {
            return 'D';
        }

        throw new RuntimeException('Scores below 60 are not eligible for automatic placement.');
    }
}
