"""
Simplified A2A Server for {{ agent_name }} Agent
Generated by ABI-Core scaffolding
"""

import logging
import asyncio
from typing import Callable, Any
from pathlib import Path

logger = logging.getLogger(__name__)

def start_server(
    host: str,
    port: int,
    agent_card_path: str,
    agent_factory: Callable[[str], Any]
):
    """
    Start the agent server
    
    Args:
        host: Server host
        port: Server port
        agent_card_path: Path to agent card JSON
        agent_factory: Factory function to create agent instance
    """
    try:
        # Create agent instance
        agent = agent_factory(agent_card_path)
        
        logger.info(f"🚀 Starting {{ agent_name }} server on {host}:{port}")
        logger.info(f"📄 Using agent card: {agent_card_path}")
        
        # Simple server loop (replace with actual A2A implementation)
        asyncio.run(_run_server(agent, host, port))
        
    except Exception as e:
        logger.error(f"❌ Failed to start server: {e}")
        raise

async def _run_server(agent: Any, host: str, port: int):
    """
    Simple server implementation
    
    Args:
        agent: Agent instance
        host: Server host
        port: Server port
    """
    logger.info(f"✅ {{ agent_name }} server running on {host}:{port}")
    logger.info("🔄 Server ready to accept connections")
    
    try:
        # Keep server running
        while True:
            await asyncio.sleep(1)
            
    except KeyboardInterrupt:
        logger.info("🛑 Server stopped by user")
    except Exception as e:
        logger.error(f"💥 Server error: {e}")
        raise