#!/usr/bin/env python3
"""Remove PM-KUSUM (FC window ended 31.03.2026; phase-2 not yet catalogued)."""
import re
from pathlib import Path

path = Path(r"E:\Startup\vedica\database\seeders\SchemeSeeder.php")
text = path.read_text(encoding="utf-8")
REMOVE = {"PM-KUSUM"}

start = text.index("return [")
end = text.rindex("];", start)
header = text[: start + len("return [")]
footer = text[end:]
body = text[start + len("return [") : end]

items = []
i = 0
n = len(body)
while i < n:
    while i < n and body[i] in " \t\r\n,":
        i += 1
    if i >= n:
        break
    if body.startswith("//", i):
        nl = body.find("\n", i)
        i = n if nl < 0 else nl + 1
        continue
    if body[i] != "[":
        raise SystemExit(f"Expected '[' at {i}: {body[i:i+40]!r}")
    depth = 0
    j = i
    in_str = False
    str_ch = ""
    escape = False
    while j < n:
        ch = body[j]
        if in_str:
            if escape:
                escape = False
            elif ch == "\\":
                escape = True
            elif ch == str_ch:
                in_str = False
        else:
            if ch in ("'", '"'):
                in_str = True
                str_ch = ch
            elif ch == "[":
                depth += 1
            elif ch == "]":
                depth -= 1
                if depth == 0:
                    j += 1
                    items.append(body[i:j])
                    i = j
                    break
        j += 1
    else:
        raise SystemExit("Unbalanced")

kept, removed = [], []
for item in items:
    m = re.search(r"'short'\s*=>\s*'([^']+)'", item)
    short = m.group(1)
    if short in REMOVE:
        removed.append(short)
    else:
        kept.append(item.strip())

if set(removed) != REMOVE:
    raise SystemExit(f"removed={removed}")

new_body = "\n            " + ",\n            ".join(kept) + ",\n        "
path.write_text(header + new_body + footer, encoding="utf-8")
print(f"Removed: {removed}; kept {len(kept)}")
