#!/opt/homebrew/bin/python3.11
"""
Debug script to test face registration with same arguments Rust uses
"""

import subprocess
import os

# Simulate what Rust would call
image_path = "/tmp/face_analysis_results/384b0ff44aaaa1f1_frame_019778.jpg"
output_path = "/tmp/face_registration_debug.json"
name = "Debug Person"
database_path = "/tmp/face_database.json"

# Create metadata file
metadata_path = "/tmp/face_metadata_debug.json"
import json

metadata = {"source": "debug", "test": True}
with open(metadata_path, "w") as f:
    json.dump(metadata, f)

# Build command
cmd = [
    "/opt/homebrew/bin/python3.11",
    "scripts/face_registration.py",
    image_path,
    output_path,
    name,
    "--database",
    database_path,
    "--metadata",
    metadata_path,
]

print(f"Running command: {' '.join(cmd)}")
print(f"Current directory: {os.getcwd()}")

# Run command
result = subprocess.run(cmd, capture_output=True, text=True)

print(f"Return code: {result.returncode}")
print(f"Stdout:\n{result.stdout}")
print(f"Stderr:\n{result.stderr}")

# Check if output file was created
if os.path.exists(output_path):
    print(f"Output file exists: {output_path}")
    with open(output_path, "r") as f:
        content = f.read()
    print(f"Output content: {content}")
else:
    print(f"Output file does not exist: {output_path}")
