const { ListResponse } = require("../../../utils/ListResponse");
const { formatISOWithoutTimezone } = require("../../../utils/FormatDate.js");

const formatItem = (item) => ({
    ...item,
    createdAt: formatISOWithoutTimezone(item.createdAt),
    updatedAt: formatISOWithoutTimezone(item.updatedAt)
});

exports.HospitalCollection = (req, res, data = [], total = null, page = 1, limit = 10, message = 'Success') => {
    const formattedData = data.map(formatItem);

    if (typeof total !== 'number') {
        return res.status(200).json({
            success: true,
            message,
            data: Array.isArray(formattedData)
        });
    }

    return ListResponse({ req, res, data: formattedData, total, page, limit, message });
};