"""Gemini 4 twins of the 8 cars Astra drew (15 Oct 2026 ~16:50 CET, operator: "re-do the cars Astra did, but with Gemini 4 now,
I want to see the difference"). Each twin gets Astra's FIRST brief and the SAME reference sheet (road cars: the v1 job from git,
before Astra's revision round), its own slug <slug>-g4 (own Blender dir on gex44, own card id) and status "candidate": shown in
the library and showroom, never picked by a game until the operator chooses.
usage: python3 tools/vehicles/make_jobs_g4twins.py   (order -> /tmp/g4cars-20261015/order.txt, one job dir per line)"""
import json, os, subprocess

ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
SCR = '/tmp/g4cars-20261015'
CARS = ['gt-racer', 'stock-car', 'le-mans-prototype', 'classic-saloon', 'euro-hatchback', 'sports-coupe', 'family-suv', 'family-sedan']


def src(job, name):
    """a file of an Astra job: the job dir, else git (the 14 Oct cleanup archived the road-car job dirs)"""
    p = f'{ROOT}/jobs/{job}/{name}'
    if os.path.exists(p):
        return open(p, 'rb').read()
    return subprocess.run(['git', '-C', ROOT, 'show', f'HEAD:jobs/{job}/{name}'], capture_output=True, check=True).stdout


def main():
    os.makedirs(SCR, exist_ok=True)
    order = []
    for slug in CARS:
        j = json.loads(src(f'{slug}-v1', 'job.json'))
        cls = j['id'].split('/')[0]
        j.update(id=f'{cls}/{slug}-g4', slug=f'{slug}-g4', version=1, pen='gemini4', status='candidate', twin_of=f'{cls}/{slug}')
        jd = f'{ROOT}/jobs/{slug}-g4-v1'
        os.makedirs(jd, exist_ok=True)
        json.dump(j, open(f'{jd}/job.json', 'w'), indent=1)
        for r in j['refs']:
            open(f'{jd}/{r}', 'wb').write(src(f'{slug}-v1', r))
        order.append(jd)
    open(f'{SCR}/order.txt', 'w').write('\n'.join(order) + '\n')
    print(len(order), 'jobs ->', f'{SCR}/order.txt')


if __name__ == '__main__':
    main()
