<?php

use CodeIgniter\Test\CIUnitTestCase;

/**
 * @internal
 */
final class EvaluationEngineServiceTest extends CIUnitTestCase
{
    public function testWeightedAverageIsCalculated(): void
    {
        $service = service('evaluationEngine');

        $score = $service->calculateFinalScore([
            ['score' => 5, 'weight' => 2, 'is_critical' => true],
            ['score' => 3, 'weight' => 1, 'is_critical' => false],
        ]);

        $this->assertSame(4.33, $score);
    }

    public function testCriticalCriterionBlocksReadyStatus(): void
    {
        $service = service('evaluationEngine');

        $result = $service->evaluate([
            ['score' => 4.8, 'weight' => 1.2, 'is_critical' => true],
            ['score' => 2.8, 'weight' => 1.4, 'is_critical' => true],
            ['score' => 4.5, 'weight' => 0.8, 'is_critical' => false],
        ], [
            'almost_ready_threshold' => 3.5,
            'ready_threshold' => 4.0,
            'minimum_critical_threshold' => 3.0,
        ]);

        $this->assertSame('ALMOST READY', $result['final_status']);
        $this->assertFalse($result['promotion_signal']);
    }

    public function testReadyCriteriaReturnPromotionSignal(): void
    {
        $service = service('evaluationEngine');

        $result = $service->evaluate([
            ['score' => 4.3, 'weight' => 1.2, 'is_critical' => true],
            ['score' => 4.4, 'weight' => 1.4, 'is_critical' => true],
            ['score' => 4.2, 'weight' => 0.8, 'is_critical' => false],
        ], [
            'almost_ready_threshold' => 3.5,
            'ready_threshold' => 4.0,
            'minimum_critical_threshold' => 3.0,
        ]);

        $this->assertSame('READY', $result['final_status']);
        $this->assertTrue($result['promotion_signal']);
    }
}
