"""Storage: SQLite database handler."""

from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker

from .models import Base

def get_engine(db_path: str):
    """Creates a SQLAlchemy engine.

    Args:
        db_path: Path to the SQLite database file.

    Returns:
        A SQLAlchemy engine instance.
    """
    return create_engine(f"sqlite:///{db_path}")

def get_session(engine):
    """Creates a session factory and returns a session.

    Args:
        engine: A SQLAlchemy engine instance.

    Returns:
        A SQLAlchemy session.
    """
    Session = sessionmaker(bind=engine)
    return Session()

def init_db(engine):
    """Creates all tables in the database.

    Args:
        engine: A SQLAlchemy engine instance.
    """
    Base.metadata.create_all(engine)