#!/usr/bin/env python3
"""Poll patched selector 2:0 diagnostics with active descriptor order watch values."""
from __future__ import annotations

from argparse import Namespace

import probe_runtime_input_path as runtime_input
from probe_runtime_input_path import DEFAULT_PREFIX, OUT
from probe_runtime_selected_pointer_multislot_savedata_poll import build_summary
from probe_runtime_selected_pointer_poll import write_outputs


OUTPUT_PREFIX = "runtime_selected_pointer_patched_public_selector_2_0_active_order_poll"
ACTIVE_ORDER_WATCH_VALUES = {
    "activeOrderCount": (0x004576E8, 1),
    "activeOrder0": (0x004576E9, 1),
    "activeOrder1": (0x004576EA, 1),
    "activeOrder2": (0x004576EB, 1),
    "activeSlot0Descriptor": (0x00457750, 4),
    "activeSlot1Descriptor": (0x00457828, 4),
    "activeSlot2Descriptor": (0x00457900, 4),
    "runtimeSlotBaseTable0": (0x0059DB30, 4),
    "runtimeSlotBaseTable1": (0x0059DB34, 4),
    "runtimeSlotBaseTable2": (0x0059DB38, 4),
    "runtimeObjectTable0": (0x0059DD70, 4),
    "runtimeObjectTable1": (0x0059DD74, 4),
    "runtimeObjectTable2": (0x0059DD78, 4),
}


def main() -> None:
    runtime_input.ROUTE_WATCH_VALUES = dict(runtime_input.ROUTE_WATCH_VALUES)
    runtime_input.ROUTE_WATCH_VALUES.update(ACTIVE_ORDER_WATCH_VALUES)
    args = Namespace(
        startup_wait=18.0,
        hold=0.7,
        gap=0.25,
        interval=0.02,
        prelude="input-path",
        sequence=[
            "input-path-slot1-down-enter=Down,Return",
            "input-path-slot1-down-enter-enter=Down,Return,Return",
        ],
        slot_source=["1=out/runtime_patched_public_savedat_selector_2_0.dat"],
        case_aliases=True,
        staged_kind="patched public-base diagnostic active-order watch",
        prefix=DEFAULT_PREFIX,
        out_dir=OUT,
        output_prefix=OUTPUT_PREFIX,
    )
    summary = build_summary(args)
    summary["objective"] = "patched public-base selector 2:0 diagnostic poll with active order/count watch values"
    summary["activeOrderWatchValues"] = ACTIVE_ORDER_WATCH_VALUES
    write_outputs(summary, OUT, OUTPUT_PREFIX)
    print(f"wrote patched selector active-order poll -> {OUT / (OUTPUT_PREFIX + '.html')}")


if __name__ == "__main__":
    main()
