# ============================================================
# src/accountable_record/stage_080_generated/compare.py
# ============================================================
"""Reconcile stage 080 generated artifacts against the stage 070 lock.

WHY:
    Stage 080 verifies that the generated artifacts present on disk and the
    element records locked by stage 070 agree. This is structural parity plus,
    when both sides carry a digest, a digest comparison. The lock records the
    expected digest per element; the generated registry carries the digest
    recomputed over the artifact's canonical form.

OBS:
    The comparison is element-scoped. Package lock records are not compared
    here. This op derives reconciliation facts only: it reads no files, emits
    no diagnostics, and mutates no state.
"""

from accountable_record.stage_070_resolution.model import ElementsLock
from accountable_record.stage_080_generated.model import (
    GeneratedReconciliation,
    GeneratedRegistry,
)

__all__ = ["reconcile_generated_with_lock"]


def reconcile_generated_with_lock(
    registry: GeneratedRegistry,
    lock: ElementsLock,
) -> GeneratedReconciliation:
    """Reconcile generated artifacts against locked elements.

    OBS:
        The lock is scoped to resolved package-included elements. Therefore this
        comparison is one-way: locked elements must have generated artifacts,
        but generated artifacts are not required to be locked.
    """
    generated_ids = registry.compact_ids()
    locked_ids = lock.element_ids()

    return GeneratedReconciliation(
        lock_missing_generated=tuple(sorted(locked_ids - generated_ids)),
        digest_mismatches=(),
    )
