"""Create the private synthetic GitLab fixture; prints the MR URL and note ID."""
import concurrent.futures
import json
import subprocess
import time

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

project = api('projects', {'name': f'award-pagination-proof-{int(time.time())}', 'visibility': 'private', 'initialize_with_readme': True})
root = f"projects/{project['id']}"
api(root + '/repository/commits', {'branch': 'reaction-proof', 'start_branch': 'main', 'commit_message': 'Synthetic reaction fixture', 'actions': [{'action': 'create', 'file_path': 'proof.txt', 'content': 'Reaction pagination proof'}]})
mr = api(root + '/merge_requests', {'source_branch': 'reaction-proof', 'target_branch': 'main', 'title': 'Reaction pagination proof'})
note = api(root + '/merge_requests/1/notes', {'body': 'Remove the thumbs up reaction, then reload to verify it stays removed.'})
endpoints = [root + '/merge_requests/1/award_emoji', root + f"/merge_requests/1/notes/{note['id']}/award_emoji"]
names = 'heart tada rocket eyes smile grin laughing blush sunglasses thinking facepalm sob cry angry rage confused worried sweat joy fire'.split()
for endpoint in endpoints:
    with concurrent.futures.ThreadPoolExecutor(max_workers=4) as executor:
        list(executor.map(lambda name: api(endpoint, {'name': name}), names))
    api(endpoint, {'name': 'thumbsup'})
print(json.dumps({'url': mr['web_url'], 'awardEndpoints': endpoints}))
