from __future__ import annotations

import hashlib
import unicodedata

QUICK_CONNECT_HOST_PROFILE_PREFIX = "xgrids.lixelkity-k1.quick-connect.fw-3.v2"


def quick_connect_host_profile_id(device_ap_ssid: str) -> str:
    """Return an opaque, device-scoped host credential profile identifier.

    LixelGO's reviewed DeviceData model carries WiFiAP_SSID and
    WiFiAP_Password per device.  The SSID is already operator-visible, but the
    credential-store account stays opaque so neither value is mistaken for a
    universal K1 factory profile.
    """

    normalized = unicodedata.normalize("NFC", device_ap_ssid).strip()
    encoded = normalized.encode("utf-8")
    if not 1 <= len(encoded) <= 32:
        raise ValueError("K1 AP SSID must contain between 1 and 32 UTF-8 bytes")
    suffix = hashlib.sha256(encoded).hexdigest()[:24]
    return f"{QUICK_CONNECT_HOST_PROFILE_PREFIX}.{suffix}"
