"""Tests for the rules registry."""

from yaml_doctor.models import Severity
from yaml_doctor.rules import all_rules


class TestAllRules:
    def test_total_count(self):
        rules = all_rules()
        assert len(rules) == 60

    def test_unique_ids(self):
        rules = all_rules()
        ids = [r.rule_id for r in rules]
        assert len(ids) == len(set(ids))

    def test_all_have_required_fields(self):
        for r in all_rules():
            assert r.rule_id
            assert r.category
            assert isinstance(r.severity, Severity)
            assert r.title
            assert r.description
            assert r.fix

    def test_kubernetes_rules(self):
        rules = [r for r in all_rules() if r.rule_id.startswith("K8S")]
        assert len(rules) == 20

    def test_compose_rules(self):
        rules = [r for r in all_rules() if r.rule_id.startswith("DC")]
        assert len(rules) == 12

    def test_github_actions_rules(self):
        rules = [r for r in all_rules() if r.rule_id.startswith("GHA")]
        assert len(rules) == 10

    def test_gitlab_ci_rules(self):
        rules = [r for r in all_rules() if r.rule_id.startswith("GL")]
        assert len(rules) == 10

    def test_yaml_rules(self):
        rules = [r for r in all_rules() if r.rule_id.startswith("YML")]
        assert len(rules) == 8

    def test_severity_distribution(self):
        rules = all_rules()
        severities = {s: sum(1 for r in rules if r.severity == s) for s in Severity}
        assert severities[Severity.CRITICAL] >= 3
        assert severities[Severity.HIGH] >= 10
        assert severities[Severity.MEDIUM] >= 10
