# ============================================================
# src/accountable_record/stage_070_resolution/transform.py
# ============================================================
"""s070 resolution stage transform."""

from accountable_record.pipeline.context import PipelineState
from accountable_record.pipeline.diagnostics import Concern
from accountable_record.pipeline.stages import stage
from accountable_record.stage_070_resolution.validation import validate_resolution_stage

STAGE_CODE = "s070"


@stage(STAGE_CODE, Concern.RESOLUTION, "Resolve references and verify lock state.")
def transform_resolution(state: PipelineState) -> PipelineState:
    """Resolve target repository references and accumulate the result."""
    result = validate_resolution_stage(state)

    if result.has_errors or result.resolution is None:
        return state.with_failure(STAGE_CODE, result.diagnostics)

    return state.with_resolution(result.resolution, result.diagnostics)
