"""Create synthetic GitLab data for the visible review handoff scenario.
Requires glab authenticated to gitlab.com; prints fixture IDs and URLs.
"""
import json
import subprocess
import time

def api(endpoint, data):
    result = subprocess.run(['glab', 'api', endpoint, '-X', 'POST', '--input', '-'], input=json.dumps(data), text=True, capture_output=True, check=True)
    return json.loads(result.stdout)

project = api('projects', {'name': 'total-proof-44088-' + str(int(time.time())), 'visibility': 'private', 'initialize_with_readme': True, 'default_branch': 'main'})
project_id = project['id']
api(f'projects/{project_id}/repository/branches', {'branch': 'fix-total', 'ref': 'main'})
api(f'projects/{project_id}/repository/commits', {'branch': 'fix-total', 'commit_message': 'Add total', 'actions': [{'action': 'create', 'file_path': 'total.txt', 'content': 'total = 1\n'}]})
mr = api(f'projects/{project_id}/merge_requests', {'source_branch': 'fix-total', 'target_branch': 'main', 'title': 'Fix wrong total'})
api(f'projects/{project_id}/merge_requests/{mr["iid"]}/discussions', {'body': '<!--' + 'x' * 1200 + '-->\nFix wrong total'})
print(json.dumps({'id': project_id, 'url': project['http_url_to_repo'], 'mr': mr['iid'], 'web': mr['web_url']}))
