# region TestStages [TYPE Module]
# @RELATION DEPENDS_ON ->[ComplianceStages]
# @SEMANTICS: tests, clean-release, compliance, stages
# @PURPOSE: Validate final status derivation logic from stage results.
# @LAYER Domain

from src.models.clean_release import (
    CheckFinalStatus,
    CheckStageResult,
    CheckStageStatus,
)
from src.services.clean_release.stages import MANDATORY_STAGE_ORDER, derive_final_status


# region test_derive_final_status_compliant [TYPE Function]
# @RELATION  BINDS_TO -> TestStages
# @PURPOSE: Verify derive_final_status returns compliant when all stages pass.
def test_derive_final_status_compliant():
    results = [
        CheckStageResult(stage=s, status=CheckStageStatus.PASS, details="ok")
        for s in MANDATORY_STAGE_ORDER
    ]
    assert derive_final_status(results) == CheckFinalStatus.COMPLIANT


# endregion test_derive_final_status_compliant


# region test_derive_final_status_blocked [TYPE Function]
# @RELATION  BINDS_TO -> TestStages
# @PURPOSE: Verify derive_final_status returns blocked when any stage fails.
def test_derive_final_status_blocked():
    results = [
        CheckStageResult(stage=s, status=CheckStageStatus.PASS, details="ok")
        for s in MANDATORY_STAGE_ORDER
    ]
    results[1].status = CheckStageStatus.FAIL
    assert derive_final_status(results) == CheckFinalStatus.BLOCKED


# endregion test_derive_final_status_blocked


# region test_derive_final_status_failed_missing [TYPE Function]
# @RELATION  BINDS_TO -> TestStages
# @PURPOSE: Verify derive_final_status returns failed when required stages are missing.
def test_derive_final_status_failed_missing():
    results = [
        CheckStageResult(
            stage=MANDATORY_STAGE_ORDER[0], status=CheckStageStatus.PASS, details="ok"
        )
    ]
    assert derive_final_status(results) == CheckFinalStatus.FAILED


# endregion test_derive_final_status_failed_missing


# region test_derive_final_status_failed_skipped [TYPE Function]
# @RELATION  BINDS_TO -> TestStages
# @PURPOSE: Verify derive_final_status returns failed when critical stages are skipped.
def test_derive_final_status_failed_skipped():
    results = [
        CheckStageResult(stage=s, status=CheckStageStatus.PASS, details="ok")
        for s in MANDATORY_STAGE_ORDER
    ]
    results[2].status = CheckStageStatus.SKIPPED
    assert derive_final_status(results) == CheckFinalStatus.FAILED


# endregion test_derive_final_status_failed_skipped
# endregion TestStages
