"""Tests for Euro NCAP scoring."""

import pytest

from impakt.criteria.base import CriterionResult
from impakt.protocol.euro_ncap import EuroNCAP, evaluate


class TestEuroNCAP:
    @pytest.fixture
    def good_criteria(self):
        """Criteria results that should score well."""
        return {
            "HIC15": CriterionResult(criterion="HIC15", value=400, body_region="Head"),
            "3ms Clip": CriterionResult(
                criterion="3ms Clip", value=38, unit="g", body_region="Chest"
            ),
            "Chest Deflection": CriterionResult(
                criterion="Chest Deflection", value=20, unit="mm", body_region="Chest"
            ),
            "Nij": CriterionResult(criterion="Nij", value=0.4, body_region="Neck"),
            "Femur Load Left": CriterionResult(
                criterion="Femur Load Left", value=3.0, unit="kN", body_region="Femur Left"
            ),
            "Femur Load Right": CriterionResult(
                criterion="Femur Load Right", value=3.2, unit="kN", body_region="Femur Right"
            ),
        }

    @pytest.fixture
    def poor_criteria(self):
        """Criteria results that should score poorly."""
        return {
            "HIC15": CriterionResult(criterion="HIC15", value=1200, body_region="Head"),
            "3ms Clip": CriterionResult(
                criterion="3ms Clip", value=65, unit="g", body_region="Chest"
            ),
            "Chest Deflection": CriterionResult(
                criterion="Chest Deflection", value=70, unit="mm", body_region="Chest"
            ),
            "Nij": CriterionResult(criterion="Nij", value=1.5, body_region="Neck"),
        }

    def test_good_results_high_stars(self, good_criteria):
        result = evaluate(good_criteria)
        assert result.stars is not None
        assert result.stars >= 4  # Good results should get 4-5 stars

    def test_poor_results_low_stars(self, poor_criteria):
        result = evaluate(poor_criteria)
        assert result.stars is not None
        assert result.stars <= 2

    def test_result_has_region_scores(self, good_criteria):
        result = evaluate(good_criteria)
        assert len(result.region_scores) > 0

    def test_result_has_colors(self, good_criteria):
        result = evaluate(good_criteria)
        for rs in result.region_scores:
            assert rs.color is not None

    def test_result_summary(self, good_criteria):
        result = evaluate(good_criteria)
        summary = result.summary()
        assert "Euro NCAP" in summary
        assert "stars" in summary

    def test_protocol_name(self):
        scorer = EuroNCAP()
        assert scorer.protocol_name == "Euro NCAP"
