# tiny_provision — the board's own name. `tiny-tech flash` reads ap_ssid() and enrols the row under it,
# so the thing in the room and the row in the cloud have ONE name.
try:
    import machine
except ImportError:  # host-side tests
    machine = None


def uid_tag(uid):
    """Four hex chars that depend on EVERY byte of the unique id (FNV-1a) — a plain suffix collides on
    same-lot boards."""
    h = 0x811C9DC5
    for b in uid:
        h ^= b
        h = (h * 0x01000193) & 0xFFFFFFFF
    return "%04x" % (h & 0xFFFF)


def ap_ssid():
    uid = machine.unique_id() if machine else b"\x00" * 12
    return "tiny-" + uid_tag(uid)
