"""
Task: task00004-260207-10.00
작업: 멀티에이전트 병렬 실행 데모 - Backend/Frontend/Data 에이전트 시뮬레이션
"""
import asyncio
import time

agents = {
    "Backend": {"icon": "[BE]", "time": 1.5, "findings": [
        "+ CRUD API well defined",
        "! Missing: /api/documents/:id/share",
        "! Missing: /api/users endpoint",
        "* Suggest: Add pagination params"
    ]},
    "Frontend": {"icon": "[FE]", "time": 1.8, "findings": [
        "+ 7 core screens defined",
        "! Missing: /docs/:id/history",
        "! Missing: /admin dashboard",
        "* Suggest: Mobile bottom nav"
    ]},
    "Data": {"icon": "[DB]", "time": 2.0, "findings": [
        "+ Core tables defined",
        "! Missing: Tag table",
        "! Missing: Link table (backlinks)",
        "* Suggest: GIN index on content"
    ]}
}

async def agent_work(name, info):
    start = time.time()
    print(f"\n{info['icon']} {name} Agent STARTED...")
    await asyncio.sleep(info['time'])
    elapsed = time.time() - start
    print(f"{info['icon']} {name} Agent DONE ({elapsed:.2f}s)")
    for f in info['findings']:
        print(f"    {f}")
    return elapsed

async def main():
    print("=" * 50)
    print("  INSUWIKI MULTI-AGENT PARALLEL DEMO")
    print("=" * 50)
    print("\n>>> Launching 3 agents in PARALLEL...\n")
    
    start = time.time()
    results = await asyncio.gather(*[agent_work(n, i) for n, i in agents.items()])
    total = time.time() - start
    
    print("\n" + "=" * 50)
    print("  SUMMARY")
    print("=" * 50)
    print(f"  Sequential would take: {sum(results):.2f}s")
    print(f"  Parallel took:         {total:.2f}s")
    print(f"  Time saved:            {sum(results) - total:.2f}s")
    print("=" * 50)

if __name__ == "__main__":
    asyncio.run(main())
