/**
 * Utility to format DB rows / repository results into a consistent API DTO (camelCase).
 */
function formatGroupListRow(row) {
    return {
        groupId: row.group_id,
        year: row.year,
        title: row.title,
        description: row.description,
        name: row.name,
        uploadDate: row.upload_date,
        approved: Boolean(row.approved),
        imageCount: row.image_count ? Number(row.image_count) : 0,
        previewImage: row.preview_image || null
    };
}

function formatGroupDetail(groupRow, images) {
    return {
        groupId: groupRow.group_id,
        year: groupRow.year,
        title: groupRow.title,
        description: groupRow.description,
        name: groupRow.name,
        uploadDate: groupRow.upload_date,
        approved: Boolean(groupRow.approved),
        images: images.map(img => ({
            id: img.id,
            fileName: img.file_name,
            originalName: img.original_name,
            filePath: img.file_path,
            previewPath: img.preview_path || null,
            uploadOrder: img.upload_order,
            fileSize: img.file_size || null,
            mimeType: img.mime_type || null,
            imageDescription: img.image_description || null
        })),
        imageCount: images.length
    };
}

module.exports = {
    formatGroupListRow,
    formatGroupDetail
};
