from sqlalchemy.engine import Engine
from sqlmodel import Session, create_engine

from infrastructure.postgres.config import PostgresConfig


def make_engine(config: PostgresConfig) -> Engine:
    return create_engine(
        config.url(),
        pool_size=config.pool_size,
        max_overflow=config.max_overflow,
        pool_pre_ping=config.pool_pre_ping,
        pool_recycle=config.pool_recycle,
    )


def make_session(engine: Engine) -> Session:
    return Session(engine)
