import 'dotenv/config';
import db from './src/database/models/index.js';
const { QuestionnaireResponse } = (db as any).default || db;

const applicationId = '6139d6f9-f3c1-4e55-903b-3516d3a08955';

async function checkSize() {
    try {
        if (!QuestionnaireResponse) {
             console.error('QuestionnaireResponse model not found.');
             return;
        }
        const responses = await QuestionnaireResponse.findAll({
            where: { applicationId }
        });

        console.log(`Found ${responses.length} responses.`);
        let totalSize = 0;
        responses.forEach((r: any, i: number) => {
            const size = r.responseValue ? r.responseValue.length : 0;
            totalSize += size;
            if (size > 100000) {
                console.log(`Response ${i} (ID: ${r.id}) size: ${Math.round(size / 1024)} KB`);
            }
        });
        console.log(`Total responseValue size: ${Math.round(totalSize / 1024)} KB`);

    } catch (error) {
        console.error('Error checking size:', error);
    } finally {
        process.exit();
    }
}

checkSize();
