# ============================================================
# src/accountable_record/stage_090_docs/transform.py
# ============================================================
"""s090 docs 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_090_docs.validation import validate_docs_stage

__all__ = ["STAGE_CODE", "transform_docs"]

STAGE_CODE = "s090"


@stage(STAGE_CODE, Concern.DOCS, "Render and validate documentation.")
def transform_docs(state: PipelineState) -> PipelineState:
    """Render/validate documentation and accumulate the result."""
    result = validate_docs_stage(state)

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

    return state.with_docs(result.docs, result.diagnostics)
