const fs = require('fs');
const ProcessImage = require('./ProcessImage');
const imgConfig = require('./../../config/image.json');

async function PosterImage(raw, hash) {
    try {
        if (!fs.existsSync(raw)) {
            console.error(`Plik wejściowy nie istnieje: ${raw}`);
            return null;
        }

        const posterSize = imgConfig.poster;
        const miniatureSize = imgConfig.miniature;

        const poster = await ProcessImage(raw, hash, 'poster', posterSize);
        const miniature = await ProcessImage(raw, hash, 'miniature', miniatureSize);

        return {poster: poster, miniature: miniature, format: imgConfig.format};
    }
    catch(e) {
        console.error(`POSTER IMAGE ERROR: ${e}`);
    }
}

module.exports = PosterImage;