"""Tests for sre_beacon.analyzers.maturity_analyzer."""

import pytest

from sre_beacon.analyzers.maturity_analyzer import (
    assess_maturity,
    assess_maturity_from_file,
)
from sre_beacon.models import MaturityLevel


class TestAssessMaturity:
    def test_full_maturity(self, full_maturity_data):
        report = assess_maturity(full_maturity_data)
        assert len(report.dimensions) == 8
        assert report.overall_score >= 4.5
        assert report.overall_level == MaturityLevel.OPTIMIZING

    def test_minimal_maturity(self, minimal_maturity_data):
        report = assess_maturity(minimal_maturity_data)
        assert report.overall_score < 1.0
        assert report.overall_level == MaturityLevel.INITIAL

    def test_dimensions_have_findings(self, full_maturity_data):
        report = assess_maturity(full_maturity_data)
        for dim in report.dimensions:
            assert len(dim.findings) > 0

    def test_minimal_has_recommendations(self, minimal_maturity_data):
        report = assess_maturity(minimal_maturity_data)
        for dim in report.dimensions:
            assert len(dim.recommendations) > 0

    def test_weakest_strongest(self, full_maturity_data):
        report = assess_maturity(full_maturity_data)
        assert report.strongest_dimension is not None
        assert report.weakest_dimension is not None

    def test_from_file(self, demo_dir):
        report = assess_maturity_from_file(demo_dir["maturity"])
        assert len(report.dimensions) == 8
        assert 2.0 <= report.overall_score <= 4.5

    def test_partial_data(self):
        data = {
            "slo_adoption": {"has_slos": True, "slo_count": 3},
            "incident_management": {"has_incident_process": True},
        }
        report = assess_maturity(data)
        assert len(report.dimensions) == 8
        slo_dim = report.dimensions[0]
        assert slo_dim.score > 0

    def test_empty_assessment(self):
        report = assess_maturity({})
        assert len(report.dimensions) == 8
        assert report.overall_score < 1.0
