import difflib
from pathlib import Path

PROJECT_ROOT = Path(r"c:\Projects\FreeExile")
from verify_replacements import PROPOSED_REPLACEMENTS, get_modified_content

patch_lines = []
for rel_path in sorted(PROPOSED_REPLACEMENTS.keys()):
    orig_file = PROJECT_ROOT / rel_path
    orig_text = orig_file.read_text(encoding="utf-8").splitlines()
    mod_text = get_modified_content(rel_path).splitlines()
    
    diff = list(difflib.unified_diff(
        orig_text,
        mod_text,
        fromfile=f"a/{rel_path.replace(chr(92), '/')}",
        tofile=f"b/{rel_path.replace(chr(92), '/')}",
        lineterm=""
    ))
    patch_lines.extend(diff)

patch_content = "\n".join(patch_lines) + "\n"
patch_path = Path(__file__).resolve().parent / "parentheticals_remediation.patch"
patch_path.write_text(patch_content, encoding="utf-8")
print(f"Generated clean patch file at {patch_path} ({len(patch_lines)} lines)")
