import re

with open("resources/js/types.ts", "r", encoding="utf-8") as f:
    content = f.read()

# Fix duplicates
content = content.replace("  updated_at?: string;\n  created_at?: string;", "  updated_at?: string;")

# Add to Lead correctly
lead_interface_regex = r"(export interface Lead \{[^}]*?)(status\?: [^;]+;)(\s*)(updated_at\?: string;)?([^}]*?\})"

def replace_lead(m):
    return m.group(1) + m.group(2) + m.group(3) + "updated_at?: string;\n  created_at?: string;" + m.group(5)

content = re.sub(lead_interface_regex, replace_lead, content)

with open("resources/js/types.ts", "w", encoding="utf-8") as f:
    f.write(content)
