import { successResponse, errorResponse } from "../utils/response.js";
import { HTTP_STATUS } from "../constants/index.js";
import logger from "../utils/logger.js";
import { getStaticDataForCategory } from "../services/blogStaticData.service.js";

export const getStaticData = async (req, res, next) => {
  try {
    const { category } = req.params;
    if (!category) {
      return errorResponse(res, "Blog category is required", HTTP_STATUS.BAD_REQUEST);
    }

    const staticData = await getStaticDataForCategory(category);
    
    // Return success even if static data is not found
    // The frontend will use the config as fallback
    if (!staticData) {
      return successResponse(res, { 
        category,
        message: "Static data file not found, use frontend config",
        data: null 
      }, HTTP_STATUS.OK);
    }

    return successResponse(res, staticData, HTTP_STATUS.OK);
  } catch (err) {
    logger.error("Error getting static data:", err);
    next(err);
  }
};

