"""Tests for remediation map — all 17 rules covered."""

import pytest

from apiposture_pro.enterprise.compliance.remediation_map import (
    REMEDIATION_MAP,
    ControlMapping,
    get_mapping,
)

ALL_RULES = [
    "AP001", "AP002", "AP003", "AP004", "AP005", "AP006", "AP007", "AP008",
    "AP101", "AP102", "AP103", "AP104", "AP105", "AP106", "AP107", "AP108", "AP201",
]


@pytest.mark.parametrize("rule_id", ALL_RULES)
def test_rule_has_soc2_control(rule_id):
    m = get_mapping(rule_id)
    assert m is not None
    assert m.soc2_control, f"Missing SOC2 control for {rule_id}"


@pytest.mark.parametrize("rule_id", ALL_RULES)
def test_rule_has_iso_control(rule_id):
    m = get_mapping(rule_id)
    assert m is not None
    assert m.iso27001_control, f"Missing ISO control for {rule_id}"


@pytest.mark.parametrize("rule_id", ALL_RULES)
def test_rule_has_remediation(rule_id):
    m = get_mapping(rule_id)
    assert m is not None
    assert m.remediation, f"Missing remediation for {rule_id}"


@pytest.mark.parametrize("rule_id", ALL_RULES)
def test_rule_returns_control_mapping_instance(rule_id):
    m = get_mapping(rule_id)
    assert isinstance(m, ControlMapping)


def test_all_17_rules_present():
    assert len(REMEDIATION_MAP) == 17


def test_unknown_rule_returns_none():
    result = get_mapping("UNKNOWN")
    assert result is None


def test_get_mapping_ap001_soc2():
    m = get_mapping("AP001")
    assert m.soc2_control == "CC6.1"


def test_get_mapping_ap201_iso():
    m = get_mapping("AP201")
    assert m.iso27001_control == "A.14.1.3"


def test_framework_controls_soc2():
    m = get_mapping("AP001")
    controls = m.framework_controls("soc2")
    assert len(controls) == 1
    assert controls[0].startswith("SOC2")


def test_framework_controls_iso27001():
    m = get_mapping("AP001")
    controls = m.framework_controls("iso27001")
    assert len(controls) == 1
    assert controls[0].startswith("ISO")


def test_framework_controls_all():
    m = get_mapping("AP001")
    controls = m.framework_controls("all")
    assert len(controls) == 2


def test_rule_id_stored_on_mapping():
    m = get_mapping("AP101")
    assert m.rule_id == "AP101"
