#!/usr/bin/env node

const fs = require('fs');
const path = require('path');
const jdenticon = require('./jdenticon-js/dist/jdenticon-node.js');

// Test emails
const testEmails = [
    'example1@gmail.com',
    'example2@yahoo.com'
];

// Test sizes
const sizes = [64, 128];

// Create reference directory
const refDir = './reference';
if (!fs.existsSync(refDir)) {
    fs.mkdirSync(refDir);
}

// Generate reference SVGs and PNGs
testEmails.forEach(email => {
    sizes.forEach(size => {
        // Generate SVG
        const svg = jdenticon.toSvg(email, size);
        const svgFilename = `${email.replace('@', '_at_').replace('.', '_')}_${size}.svg`;
        fs.writeFileSync(path.join(refDir, svgFilename), svg);
        console.log(`Generated reference SVG: ${svgFilename}`);
        
        // Generate PNG (if supported)
        try {
            const pngBuffer = jdenticon.toPng(email, size);
            const pngFilename = `${email.replace('@', '_at_').replace('.', '_')}_${size}.png`;
            fs.writeFileSync(path.join(refDir, pngFilename), pngBuffer);
            console.log(`Generated reference PNG: ${pngFilename}`);
        } catch (err) {
            console.log(`PNG generation failed for ${email}@${size}: ${err.message}`);
        }
    });
});

// Also generate a test with fixed coordinates we can examine
const testSvg = jdenticon.toSvg('test-hash', 64);
fs.writeFileSync(path.join(refDir, 'test-hash_64.svg'), testSvg);
console.log('Generated test-hash reference SVG');

console.log('\nReference files generated in ./reference/ directory');