from flask import Flask
from flask_cors import CORS
from . import config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
import logging

# 创建 SQLAlchemy 全局实例
db = SQLAlchemy()

# 创建并配置 Flask 应用
def create_app():
    app = Flask(__name__)
    CORS(app)
    # 进行初始配置，加载配置文件等
    app.config.from_object(config.Config)
    app.logger.setLevel(logging.DEBUG)
    # 初始化 SQLAlchemy
    db.init_app(app)

    # 初始化 Flask-Migrate
    migrate = Migrate(app, db)

    # 导入路由
    from . import routes
    app.register_blueprint(routes.bp)
    return app
