<?php

declare(strict_types=1);

namespace Tournament\Scoring;

use RuntimeException;

final class DefaultScoringStrategy implements ScoringStrategy
{
    public function calculateScore(
        array $result
    ): float {
        if (
            !isset($result['score'])
            || $result['score'] === null
        ) {
            throw new RuntimeException(
                'Score is required.'
            );
        }

        if (!is_numeric($result['score'])) {
            throw new RuntimeException(
                'Score must be numeric.'
            );
        }

        return (float) $result['score'];
    }
}