from k1link.device_plugins.xgrids_k1.ble.ap_activation import (
    COMMAND_OFFSET,
    ENABLE_AP_COMMAND,
    FRAME_LENGTH,
    build_ap_activation_frame,
    is_ap_ready_status,
)
from k1link.device_plugins.xgrids_k1.ble.wifi_provisioning import WifiStatus


def test_build_ap_activation_frame_matches_reviewed_lixelgo_layout() -> None:
    frame = build_ap_activation_frame()

    assert len(frame) == FRAME_LENGTH == 100
    assert frame[COMMAND_OFFSET] == ENABLE_AP_COMMAND == 1
    assert frame[:COMMAND_OFFSET] == bytes(COMMAND_OFFSET)


def _status(*, reserved: int) -> WifiStatus:
    return {
        "value_length": 52,
        "mode": "WIFI_AP",
        "ipv4": "192.168.56.1",
        "status_code": 1,
        "reserved": reserved,
        "trailer_hex": "",
    }


def test_ap_control_mode_without_ready_flag_is_not_ready() -> None:
    assert not is_ap_ready_status(_status(reserved=0))


def test_ap_ready_requires_the_reviewed_byte_51_flag() -> None:
    assert is_ap_ready_status(_status(reserved=1))
