#!/usr/bin/env python3
"""Commands used for the Android captures, after opening a new Demo task.
Run separately against each checkout's Metro and fresh server.
Arguments: SESSION SIDE OUTPUT_DIRECTORY (SIDE is base or head).
"""
import pathlib, subprocess, sys
session, side, output = sys.argv[1:]
out = pathlib.Path(output)
out.mkdir(parents=True, exist_ok=True)
def device(*args):
    return subprocess.run(["agent-device", *args, "--session", session], check=True)
device("record", "start", str(out / (side + ".mp4")), "--hide-touches")
for draft in ["/mod", "fix this /mod"]:
    device("fill", 'role="text-field"', draft, "--settle")
    device("wait", "stable", "800", "10000")
    device("press", 'label="/model, Switch model"', "--settle")
    if side == "head":
        device("press", 'label="Cancel thread settings"', "--settle")
    device("get", "attrs", 'role="text-field"')
device("record", "stop")
