""" /mgmt.py """

# Tie together the main components of the piapp flask application.

from lib.logger import logset
from lib.project import app
from lib.project import env
from lib.project import oauth
from lib.utils import apply_handler
from routes.auth import add_routes as add_auth_routes
from routes.index import add_routes as add_index_routes

log = logset("PIAPP")
log.propagate = False
log.info("Starting app 'PIAPP'")

app.secret_key = env.app_secret

oauth.register(
    "auth0",
    client_id=env.auth0.client,
    client_secret=env.auth0.secret,
    client_kwargs={"scope": "openid email profile"},
    server_metadata_url=f"https://{env.auth0.domain}/.well-known/openid-configuration",
)

add_auth_routes(app)
add_index_routes(app)

# Call this AFTER adding all the routes.
# It wraps all the routes with error handling & logging
apply_handler(app)
