"""Database connection helpers."""
import asyncpg
import redis.asyncio as aioredis
from minio import Minio

from .config import AppConfig


async def get_pg_pool(config: AppConfig) -> asyncpg.Pool:
    """Create a PostgreSQL connection pool."""
    return await asyncpg.create_pool(
        dsn=config.postgres.dsn,
        min_size=2,
        max_size=10,
    )


def get_redis(config: AppConfig) -> aioredis.Redis:
    """Create a Redis async client."""
    return aioredis.from_url(
        config.redis.url,
        decode_responses=True,
    )


def get_minio(config: AppConfig) -> Minio:
    """Create a MinIO client."""
    return Minio(
        config.minio.endpoint,
        access_key=config.minio.access_key,
        secret_key=config.minio.secret_key,
        secure=config.minio.secure,
    )
