"""Mark Phase 6 tasks as complete in state.toml."""
from __future__ import annotations

from pathlib import Path

STATE = Path("conductor/tracks/send_result_to_send_20260616/state.toml")

EDITS: list[tuple[str, str]] = [
 ('phase_6 = { status = "in_progress", checkpointsha = "", name = "Update state.toml + metadata.json + register in tracks.md" }',
  'phase_6 = { status = "completed", checkpointsha = "9a5d3b9c", name = "Update state.toml + metadata.json + register in tracks.md" }'),
 ('t6_1 = { status = "in_progress", commit_sha = "", description = "Update state.toml - mark all tasks complete" }',
  't6_1 = { status = "completed", commit_sha = "aad6deff", description = "Update state.toml - mark all tasks complete" }'),
 ('t6_2 = { status = "pending", commit_sha = "", description = "Update metadata.json - set status=shipped" }',
  't6_2 = { status = "completed", commit_sha = "5a58e1ce", description = "Update metadata.json - set status=shipped" }'),
 ('t6_3 = { status = "pending", commit_sha = "", description = "Register in conductor/tracks.md" }',
  't6_3 = { status = "completed", commit_sha = "9a5d3b9c", description = "Register in conductor/tracks.md" }'),
]


def main() -> int:
 with STATE.open("r", encoding="utf-8", newline="") as f:
  content = f.read()
 applied = 0
 for old, new in EDITS:
  if old in content:
   content = content.replace(old, new, 1)
   applied += 1
  else:
   print(f"NOT FOUND: {old[:80]!r}")
 if applied != len(EDITS):
  print(f"Only applied {applied}/{len(EDITS)} edits.")
  return 1
 with STATE.open("w", encoding="utf-8", newline="") as f:
  f.write(content)
 print(f"Applied {applied}/{len(EDITS)} edits.")
 return 0


if __name__ == "__main__":
 raise SystemExit(main())
