import io, re

p = r'C:\Users\decid\Documents\projects\spt-claude-code\tools\claude-spt\src\hook.rs'
s = io.open(p, encoding='utf-8').read()
NL = chr(10)
lines = s.split(NL)


def find_item(name, kind):
    pat = re.compile(r'^(pub )?' + kind + r' ' + re.escape(name) + r'\b')
    for i, l in enumerate(lines):
        if pat.match(l):
            start = i
            while start > 0 and (lines[start - 1].startswith('///')
                                 or lines[start - 1].startswith('//')
                                 or lines[start - 1].startswith('#[')):
                start -= 1
            j = i
            while j < len(lines) and lines[j] != '}':
                j += 1
            return start, j
    return None


TARGETS = [
    ('owl_session_state', 'fn'),
    ('park_turn_end_confirm', 'fn'),
    ('send_landed', 'fn'),
    ('SendOutcome', 'enum'),
    ('send_outcome', 'fn'),
    ('ScanConfirm', 'struct'),
    ('tag_confirm_rel', 'fn'),
    ('parked_confirm_block', 'fn'),
]

found = []
for n, k in TARGETS:
    r = find_item(n, k)
    if r is None:
        print('  (already gone or not top-level:', n, ')')
        continue
    found.append((r[0], r[1], n))

for a, b, n in sorted(found, reverse=True):
    del lines[a:b + 1]

s = NL.join(lines)
s = re.sub(NL + '{3,}', NL + NL, s)
io.open(p, 'w', encoding='utf-8', newline=NL).write(s)
print('removed:', ', '.join(n for _, _, n in sorted(found)))
