"""One-time script to insert goods/inventory domain analysis into dwd-table-structure-overview.md"""
import pathlib

DOC = pathlib.Path("docs/reports/dwd-table-structure-overview.md")
MARKER_7 = "<!-- 字段语义分析将在任务 1.7 中填充 -->\n\n## 8. 库存域"
MARKER_8 = "<!-- 字段语义分析将在任务 1.7 中填充 -->\n\n\n## 9."

# Read the section 7 and 8 content from a separate file
CONTENT_FILE = pathlib.Path("scripts/ops/_goods_inventory_content.md")

content = DOC.read_text(encoding="utf-8")
insert_content = CONTENT_FILE.read_text(encoding="utf-8")

# Split the insert content at the section 8 boundary marker
parts = insert_content.split("===SECTION_8_BOUNDARY===")
section7_content = parts[0]
section8_content = parts[1] if len(parts) > 1 else ""

# Replace section 7 placeholder
old7 = "<!-- 字段语义分析将在任务 1.7 中填充 -->\n\n## 8. 库存域"
new7 = section7_content.rstrip() + "\n\n## 8. 库存域"
content = content.replace(old7, new7, 1)

# Replace section 8 placeholder
old8 = "<!-- 字段语义分析将在任务 1.7 中填充 -->\n\n\n## 9."
new8 = section8_content.rstrip() + "\n\n\n## 9."
content = content.replace(old8, new8, 1)

DOC.write_text(content, encoding="utf-8")
print(f"Done. File size: {len(content)} chars")
