"""Enable exactly one of the two synthetic connections, ordered by when paired."""
import argparse,subprocess,re
p=argparse.ArgumentParser();p.add_argument('--session',required=True);p.add_argument('--index',type=int,required=True);a=p.parse_args()
def run(*args):
 r=subprocess.run(['agent-device',*args,'--session',a.session],capture_output=True,text=True,check=True);return r.stdout
run('press','role=button label="Settings"','--settle')
run('press','label="Environments, 2"','--settle')
for i in range(2):
 s=run('snapshot','-i');switches=re.findall(r'(@\S+) \[switch\][^\n]+',s)
 line=next(line for line in s.splitlines() if line.startswith(switches[i]+' '))
 if ('[checked]' in line)!=(i==a.index):run('press',switches[i],'--settle')
run('press','role=button label="Back"','--settle')
run('press','role=button label="Chats"','--settle')
print('Only the requested synthetic environment is enabled.')
