"""usage: revise.py <slug> "<critique>"  -> jobs/<slug>-v2 with previous files + feedback (launched by revq.sh)"""
import json, os, shutil, sys
ROOT = os.path.expanduser('~/forge-build/forge-assets')
slug, fb = sys.argv[1], sys.argv[2]
src, dst = f'{ROOT}/jobs/{slug}-v1', f'{ROOT}/jobs/{slug}-v2'
os.makedirs(dst, exist_ok=True)
j = json.load(open(f'{src}/job.json'))
j['version'] = 2
for f, g in (('sheet.jpg', 'sheet.jpg'), (f'{slug}-raw.glb', 'previous.glb'), ('final.png', 'previous_final.png'), ('side.png', 'previous_side.png'),
             (f'build_{slug}.py', f'build_{slug}.py'), ('paints.png', 'previous_paints.png')):
    if os.path.exists(f'{src}/{f}'):
        shutil.copyfile(f'{src}/{f}', f'{dst}/{g}')
j['refs'] = [r for r in ('sheet.jpg', 'previous_final.png', 'previous_side.png') if os.path.exists(f'{dst}/{r}')]
j['feedback'] = (fb + ' Keep the contract of the previous version (node names, pivots, Paint material factor, paints in nodes.json, '
                 'game weight). Start from the previous build script and change what the critique names; deliver the same files.')
json.dump(j, open(f'{dst}/job.json', 'w'), indent=1)
print(dst)
