"""gRPC server setup for {{ project_title }}.

⚠️ AUTO-GENERATED BY PRISM - DO NOT EDIT
"""

from __future__ import annotations

import logging

logger = logging.getLogger(__name__)

# gRPC server port
GRPC_PORT = {{ grpc_port }}
GRPC_REFLECTION = {{ grpc_reflection }}


async def serve() -> None:
    """Start the gRPC server.

    This function starts a grpcio async server with all registered
    service implementations. Enable reflection for debugging with
    tools like grpcurl.

    Requires: grpcio, grpcio-tools, grpcio-reflection
    Install: pip install grpcio grpcio-tools grpcio-reflection
    """
    import grpc
    from grpc_reflection.v1alpha import reflection

    server = grpc.aio.server()

    # Register service implementations here
{{ register_block }}

    # Enable reflection for debugging
    if GRPC_REFLECTION:
        service_names = [
{{ service_names_block }}
            reflection.SERVICE_NAME,
        ]
        reflection.enable_server_reflection(service_names, server)

    listen_addr = f"[::]:{GRPC_PORT}"
    server.add_insecure_port(listen_addr)
    logger.info("gRPC server starting on %s", listen_addr)
    await server.start()
    await server.wait_for_termination()


__all__ = ["serve", "GRPC_PORT", "GRPC_REFLECTION"]
