from flask import Flask
import os
from dotenv import dotenv_values



env_path = "../../containers/.env"
ENV = dotenv_values(env_path)

def create_app(test_config=None):
    # create and configure the app
    app = Flask(__name__, instance_relative_config=True)
    app.config.from_mapping(
        SECRET_KEY='6e674d6e41b733270fd01c6257b3a1b4769eb80f3f773cd0fe8eff25f350fc1f',
        POSTGRES_DB=ENV["POSTGRES_DB"],
        POSTGRES_USER=ENV["POSTGRES_USER"],
        POSTGRES_HOST=ENV["POSTGRES_HOST"],
        POSTGRES_PORT=ENV["POSTGRES_PORT"],
        POSTGRES_PASSWORD=ENV["POSTGRES_PASSWORD"],
    )



    # ensure the instance folder exists
    try:
        os.makedirs(app.instance_path)
    except OSError:
        pass

    # a simple page that says hello
    @app.route('/')
    def hello():
        return 'Hello, World!'


    from . import db_interface
    db_interface.init_database(app)

    from . import validation
    app.register_blueprint(validation.bp)

    return app


