from __future__ import annotations

import logging

import asyncpg  # type: ignore[import-untyped]

log = logging.getLogger(__name__)


async def create_pool(dsn: str) -> asyncpg.Pool:
    """
    Create an asyncpg connection pool with production defaults.
    """
    pool = await asyncpg.create_pool(
        dsn,
        min_size=2,
        max_size=100,
        command_timeout=60.0,
    )
    if pool is None:
        msg = f"Failed to create connection pool for {dsn}"
        raise RuntimeError(msg)
    log.info("Database pool created (min=2, max=100)")
    return pool
