from flask import Flask

from app.config import Config
from app.extensions import cors, db, jwt
from app.routes.admin_routes import admin_bp
from app.routes.auth_routes import auth_bp
from app.routes.content_routes import content_bp
from app.routes.spam_routes import spam_bp
from app.routes.upload_routes import upload_bp
from app.routes.user_routes import user_bp


def create_app() -> Flask:
    app = Flask(__name__)
    app.config.from_object(Config)

    db.init_app(app)
    jwt.init_app(app)
    cors.init_app(app, supports_credentials=True)

    app.register_blueprint(auth_bp, url_prefix="/api/auth")
    app.register_blueprint(user_bp, url_prefix="/api/user")
    app.register_blueprint(spam_bp, url_prefix="/api/spam")
    app.register_blueprint(content_bp, url_prefix="/api/content")
    app.register_blueprint(admin_bp, url_prefix="/api/admin")
    app.register_blueprint(upload_bp, url_prefix="/api/upload")

    @app.get("/api/health")
    def health_check():
        return {
            "code": 0,
            "message": "ok",
            "data": {
                "service": "spam-detect-backend",
                "version": "2.1.0",
            },
        }

    return app
