"""
Schools API - Database Connection.

Shared database pool for school endpoints.
"""

import os
from typing import Optional

import asyncpg

# Database connection pool
_pool: Optional[asyncpg.Pool] = None


async def get_db_pool() -> asyncpg.Pool:
    """Get or create database connection pool."""
    global _pool
    if _pool is None:
        database_url = os.environ.get(
            "DATABASE_URL",
            "postgresql://breakpilot:breakpilot123@postgres:5432/breakpilot_db"
        )
        _pool = await asyncpg.create_pool(database_url, min_size=2, max_size=10)
    return _pool
