from flask import Flask, make_response, request

from no_global_flask_app.business import my_foo, my_index, my_bar


def get_route_index():
    return "/"


def get_route_bar():
    return "/bar"


def get_route_foo():
    return "/foo"


def get_app(testing=False):
    app = Flask(__name__)
    if testing:
        app.config["TESTING"] = True
    app.add_url_rule(get_route_index(), "index", index)
    app.add_url_rule(get_route_foo(), "foo", foo)
    app.add_url_rule(get_route_bar(), "bar", bar)
    return app


def index(local_index=my_index):
    return local_index()


def foo(local_foo=my_foo):
    return local_foo()


def bar(local_bar=my_bar, qs_bar="bar"):
    return make_response(
        local_bar(request.args.get("bar")), 200, {"Content-Type": "application/json"}
    )
