#!/usr/bin/env python3
from pathlib import Path
import argparse,json,shutil
HERE=Path(__file__).resolve().parent; root=HERE/'workspace'
if not (root/'.tol001-owned').exists(): raise SystemExit('Run setup_fixture.py first')
p=argparse.ArgumentParser(); p.add_argument('mutation',choices=['add-demo-member','move-ui-config','swap-web-dependency']); args=p.parse_args()
if args.mutation=='add-demo-member':
    q=root/'workspace.json'; d=json.load(open(q,encoding='utf-8')); d['exclude']=[x for x in d.get('exclude',[]) if x!='experiments/demo'];
    if 'experiments/demo' not in d['members']: d['members'].append('experiments/demo')
    q.write_text(json.dumps(d,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
elif args.mutation=='move-ui-config':
    src=root/'apps/web/ui.policy.json'; dst=root/'packages/ui/ui.policy.json'; dst.parent.mkdir(parents=True,exist_ok=True); shutil.move(src,dst)
elif args.mutation=='swap-web-dependency':
    q=root/'apps/web/package.json'; d=json.load(open(q,encoding='utf-8')); d['dependencies']={'@demo/config':'workspace:*'}; q.write_text(json.dumps(d,ensure_ascii=False,indent=2)+'\n',encoding='utf-8')
print(args.mutation)
