from fastapi import APIRouter
from fastapi.responses import JSONResponse
import traceback

from model.product_catalog_model import ProductCatalogModel

router = APIRouter()


@router.get("/product-catalog.json")
async def get_product_catalog():
    try:
        data = ProductCatalogModel.get_product_catalog_map()
        return JSONResponse(content=data)
    except Exception as e:
        error_trace = traceback.format_exc()

        print("========== PRODUCT CATALOG ERROR ==========")
        print(f"Error type: {type(e).__name__}")
        print(f"Error detail: {str(e)}")
        print("Traceback:\n", error_trace)
        print("==========================================")

        return JSONResponse(
            status_code=500,
            content={
                "success": False,
                "message": "Không lấy được product catalog",
                "error_type": type(e).__name__,
                "error_detail": str(e),
            }
        )