from __future__ import annotations
from flask import Flask
from .home import register_home_routes
from .auth import register_auth_routes
from .admin import register_admin_routes
from .main import register_main_routes
from .xml import register_xml_routes
from .utilities import register_util_routes, utils_bp
from .file_view import register_file_view
from .jobs import register_jobs_routes
from .idrac_routes import register_idrac_routes
from .catalog_sync import catalog_bp
from .scp_routes import scp_bp
from .drm_sync import drm_sync_bp
from .server_config_routes import server_config_bp
from .bios_baseline_routes import register_bios_baseline_routes
from .script_manager import script_manager_bp


def register_routes(app: Flask, socketio=None) -> None:
    """블루프린트 일괄 등록. socketio는 main 라우트에서만 사용."""
    register_home_routes(app)
    register_auth_routes(app)
    register_admin_routes(app)
    register_main_routes(app, socketio)
    register_xml_routes(app)
    app.register_blueprint(utils_bp, url_prefix="/utils")
    register_file_view(app)
    register_jobs_routes(app)
    register_idrac_routes(app)
    app.register_blueprint(catalog_bp)
    app.register_blueprint(scp_bp)
    app.register_blueprint(drm_sync_bp)
    app.register_blueprint(server_config_bp)
    register_bios_baseline_routes(app)
    app.register_blueprint(script_manager_bp)
    
    # CSRF 제외 - server_config API 엔드포인트
    try:
        csrf = app.extensions.get('csrf')
        if csrf:
            csrf.exempt(server_config_bp)
    except Exception as e:
        app.logger.warning(f"CSRF exemption failed for server_config_bp: {e}")
