const {httpHeaders} = require("./httpResponses");

const headers = {
    [httpHeaders.JSON.name]:  httpHeaders.JSON.value
}

function sendResponse(res, statusCode, message, data = null, headers_parsed = {}) {
    Object.entries(headers).forEach(([key, value]) => {
        res.setHeader(key, value);
    });

    // Set headers if provided
    Object.entries(headers_parsed).forEach(([key, value]) => {
        res.setHeader(key, value);
    });

    // Send the response with status code, message, and optional data
    res.status(statusCode).json({ message, data });
}

module.exports = { sendResponse };