# backend/routes/catalog_sync.py
from flask import Blueprint, jsonify, request
from backend.services.dell_catalog_sync import sync_dell_catalog

catalog_bp = Blueprint("catalog", __name__, url_prefix="/catalog")

@catalog_bp.route("/sync", methods=["POST"])
def sync_catalog():
    """Dell Catalog 버전 정보를 동기화 (CSRF 보호 유지)"""
    try:
        data = request.get_json(silent=True) or {}
        model = data.get("model", "PowerEdge R750")

        sync_dell_catalog(model)
        return jsonify({
            "success": True,
            "message": f"{model} 동기화 완료"
        })
    except Exception as e:
        return jsonify({
            "success": False,
            "message": f"오류: {str(e)}"
        })
