# ============================================================
# src/accountable_record/stage_080_generated/transform.py
# ============================================================
"""s080 generated 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_080_generated.validation import validate_generated_stage

STAGE_CODE = "s080"


@stage(STAGE_CODE, Concern.GENERATED, "Validate generated artifacts.")
def transform_generated(state: PipelineState) -> PipelineState:
    """Validate generated artifacts and accumulate the result."""
    result = validate_generated_stage(state)

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

    return state.with_generated(result.generated, result.diagnostics)
