#!/usr/bin/env python3
"""vendora-vnd-id — read-only inspector for this SBC's VND-ID.

Prints the persisted VND-ID (from /etc/vendora/vnd_id) and, separately, what
this hardware would compute right now. If they differ, prints a hardware-
changed warning. Does NOT generate or overwrite — generation is the license
service's responsibility on first run, and once written the file is sacred.
"""
import sys

sys.path.insert(0, "/opt/vendora_sbc/services")
from common import vnd_id  # noqa: E402


def main() -> int:
    current = vnd_id.read()
    try:
        computed = vnd_id.compute()
        compute_err = None
    except Exception as e:
        computed = None
        compute_err = str(e)

    if current is None and computed is None:
        print(f"VND-ID:   not yet generated, AND cannot compute ({compute_err})")
        return 1

    if current is None:
        print("VND-ID:   (not yet persisted)")
        print(f"Computed: {computed}")
        print()
        print("Run the vendora-license service to persist this value.")
        print("(Until persisted, this SBC has no global identity.)")
        return 0

    print(f"VND-ID:   {current}")
    if computed and computed != current:
        print(f"Computed: {computed}")
        print()
        print("WARNING: computed value differs from persisted value.")
        print("Hardware may have changed (different SBC board, eth0 MAC swap,")
        print("or restored microSD on different hardware). DO NOT regenerate —")
        print("the license server keys off the persisted value.")
        return 2
    return 0


if __name__ == "__main__":
    sys.exit(main())
