#!/usr/bin/env python3
"""Patch tools-api main.py to register new routers."""
from pathlib import Path

p = Path("/home/aissa/foodlinkk-command-center/tools-api/app/main.py")
text = p.read_text()

if "from app.retail import router as retail_router" not in text:
    text = text.replace(
        "from app.middleware import log_agent_event",
        "from app.middleware import log_agent_event\nfrom app.retail import router as retail_router\nfrom app.research import router as research_router\nfrom app.recommendations import router as recommendations_router\nfrom app.logging_middleware import AgentLoggingMiddleware",
    )

if "app.include_router(retail_router)" not in text:
    text = text.replace(
        'app = FastAPI(title="Foodlinkk Tools API", version="1.0.0")',
        'app = FastAPI(title="Foodlinkk Tools API", version="1.1.0")\napp.add_middleware(AgentLoggingMiddleware)\napp.include_router(retail_router)\napp.include_router(research_router)\napp.include_router(recommendations_router)',
    )

p.write_text(text)
print("patched tools-api main.py")
