#!/usr/bin/env python3
"""Poll public predecessor direction sweeps with branch-state 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_predecessor_direction_sweep_branch_state_poll"
BRANCH_STATE_WATCH_VALUES = {
    "activeSelectionFlag": (0x00457744, 1),
    **{
        f"secondaryBranchState{index}": (0x0059E360 + index, 1)
        for index in range(12)
    },
}


def main() -> None:
    runtime_input.ROUTE_WATCH_VALUES = dict(runtime_input.ROUTE_WATCH_VALUES)
    runtime_input.ROUTE_WATCH_VALUES.update(BRANCH_STATE_WATCH_VALUES)
    args = Namespace(
        startup_wait=18.0,
        hold=0.7,
        gap=0.25,
        interval=0.02,
        prelude="input-path",
        sequence=[
            "predecessor-right-sweep=Down,Return,Right,Right,Right,Right,Return",
            "predecessor-left-sweep=Down,Return,Left,Left,Left,Left,Return",
            "predecessor-up-sweep=Down,Return,Up,Up,Up,Up,Return",
            "predecessor-down-sweep=Down,Return,Down,Down,Down,Down,Return",
            "predecessor-right-run=Down,Return,Right,Right,Right,Right,Right,Right",
            "predecessor-left-run=Down,Return,Left,Left,Left,Left,Left,Left",
            "predecessor-up-run=Down,Return,Up,Up,Up,Up,Up,Up",
            "predecessor-down-run=Down,Return,Down,Down,Down,Down,Down,Down",
        ],
        slot_source=["1=data/public_savedata/flack3r/savedat2.dat"],
        case_aliases=True,
        staged_kind="public predecessor direction sweep branch-state watch",
        prefix=DEFAULT_PREFIX,
        out_dir=OUT,
        output_prefix=OUTPUT_PREFIX,
    )
    summary = build_summary(args)
    summary["objective"] = "public predecessor direction sweep poll with branch-state watch values"
    summary["branchStateWatchValues"] = BRANCH_STATE_WATCH_VALUES
    write_outputs(summary, OUT, OUTPUT_PREFIX)
    print(f"wrote predecessor direction sweep branch-state poll -> {OUT / (OUTPUT_PREFIX + '.html')}")


if __name__ == "__main__":
    main()
