import os

from flask import Flask, Response

from web.routes.api import api_bp
from web.routes.views import views_bp


def create_app() -> Flask:
    """Application Factory de Flask."""
    app = Flask(__name__, template_folder="templates", static_folder="static")

    app.config["SECRET_KEY"] = os.environ.get("SECRET_KEY", "louis_is_gay")

    app.register_blueprint(views_bp)

    app.register_blueprint(api_bp, url_prefix="/api")

    @app.after_request
    def add_header(response: Response) -> Response:
        response.headers["Cache-Control"] = "no-store, no-cache, must-revalidate, max-age=0"
        response.headers["Pragma"] = "no-cache"
        response.headers["Expires"] = "0"
        return response

    return app
