#!/usr/bin/env python3
"""
Module that creates the flask app used to run JASS as a web server
"""
import connexion
import flask

from .encoder import JSONEncoder
from .config import config


class JassFlaskApp(connexion.FlaskApp):
    """
    JassFlaskApp subclasses connexion's FlaskApp only to customize the static url path
    """

    def create_app(self):
        app = flask.Flask(self.import_name, static_url_path="", static_folder="static")
        app.json_encoder = JSONEncoder
        app.route("/")(self.redirect_to_index)
        return app

    def redirect_to_index(self):
        return flask.redirect("index.html")


def get_jass_app():
    app = JassFlaskApp(__name__, specification_dir="./swagger/")
    app.add_api("swagger.yaml", arguments={"title": "JASS"}, base_path="/api")
    return app
