<?php

declare(strict_types=1);

namespace App\Services;

use App\Models\Session;

final class ScoringService
{
    /**
     * Calculate the score for a session based on scored answers.
     */
    public function calculateScore(Session $session): int
    {
        return $session->answers()
            ->whereHas('question', fn ($q) => $q->where('is_scored', true))
            ->where('value', 'yes')
            ->count();
    }

    /**
     * Determine the result based on the score.
     */
    public function determineResult(int $score): string
    {
        if ($score >= 10) {
            return 'go';
        }

        if ($score >= 5) {
            return 'consult_leadership';
        }

        return 'no_go';
    }
}
