import logging
import logging.config
from flask import Flask
import os

from common.utils.celery_utils import make_celery, init_celery
from config.logging_config import configure_logging
from config.config import get_config


def create_app(config_file=None):
    app = Flask(__name__)

    environment = os.getenv('FLASK_ENV', 'development')

    match environment:
        case 'development':
            app.config.from_object(get_config('dev'))
        case 'production':
            app.config.from_object(get_config('prod'))
        case _:
            app.config.from_object(get_config('dev'))

    configure_logging()

    register_extensions(app)

    celery = make_celery(app.name, app.config)
    init_celery(celery, app, is_beat=True)

    from . import schedule
    celery.conf.beat_schedule = schedule.beat_schedule

    app.logger.info("EveAI Beat Scheduler Started Successfully")
    app.logger.info("-------------------------------------------------------------------------------------------------")

    return app, celery


def register_extensions(app):
    pass


app, celery = create_app()
