from app.core import config
from app.schemas.user import UserCreate
from app.models.user import User as UserModel
# from app.db.session import SessionScope

# make sure all SQL Alchemy models are imported before initializing DB
# otherwise, SQL Alchemy might fail to initialize relationships properly
# for more details: https://github.com/tiangolo/full-stack-fastapi-postgresql/issues/28
from app.db import base  # noqa


def init_db():
    """Initialize the database with an admin user."""

    # Tables should be created with Alembic migrations
    # But if you don't want to use migrations, create
    # the tables un-commenting the next line
    # Base.metadata.create_all(bind=engine)

    user = UserModel.get(email=config.FIRST_SUPERUSER)
    if not user:
        user_in = UserCreate(
            email=config.FIRST_SUPERUSER,
            password=<PASSWORD>,
            is_superuser=True,
        )
        user = UserModel.create(user_in)
