# services/recipes/app/core/database.py
"""
Database configuration and session management for Recipe Service
"""

from shared.database.base import DatabaseManager, create_database_manager
from .config import settings

# Create database manager using shared async infrastructure
db_manager = create_database_manager(
    database_url=settings.DATABASE_URL,
    service_name="recipes-service",
    echo=settings.DEBUG
)

# Dependency for FastAPI routes
async def get_db():
    """FastAPI dependency to get database session"""
    async for session in db_manager.get_db():
        yield session

# Initialize database
async def init_database():
    """Initialize database tables"""
    await db_manager.create_tables()