# pylint: disable=invalid-name, wrong-import-position
import os
from sqlite3 import Connection as SQLite3Connection
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import create_engine, event, func
from sqlalchemy.orm import sessionmaker
from sqlalchemy.engine import Engine


app = Flask("gradGyde")
app.secret_key = os.getenv('SECRET_KEY')

app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///gradGyde.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
SESSION = db.session

@event.listens_for(Engine, "connect")
def _set_sqlite_pragma(dbapi_connection, _):
    if isinstance(dbapi_connection, SQLite3Connection):
        cursor = dbapi_connection.cursor()
        cursor.execute("PRAGMA foreign_keys=ON;")
        cursor.close()

from .models import init_database

init_database()


from . import main
