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

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

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

    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 });
};