import json
import subprocess
import time

def api(endpoint, **fields):
    args = ["glab", "api", "-X", "POST", endpoint]
    for key, value in fields.items():
        args += ["-F" if isinstance(value, (list, dict)) else "-f", f"{key}={json.dumps(value) if isinstance(value, (list, dict)) else value}"]
    return json.loads(subprocess.check_output(args))

project = api("projects", name=f"nfc-proof-46268-{int(time.time())}", visibility="private", initialize_with_readme="true")
pid = project["id"]
api(f"projects/{pid}/issues", title="Café fix")
api(f"projects/{pid}/repository/branches", branch="accent-proof", ref="main")
api(f"projects/{pid}/repository/commits", branch="accent-proof", commit_message="Add accent proof fixture", actions=[{"action":"create", "file_path":"proof.txt", "content":"Accent matching sample"}])
api(f"projects/{pid}/merge_requests", source_branch="accent-proof", target_branch="main", title="Accent completion proof", description="Synthetic sample for accented issue references.")
print(json.dumps({"projectId":pid,"repository":project["path_with_namespace"]}))
# Substitute the printed repository in the scenario before running it.
# After capture, remove the synthetic project with: glab api -X DELETE projects/<projectId>
