const Updater = require('./Updater');
const mkdirp = require('mkdirp');
const fs = require('fs');
const path = require('path');
const _ = require('lodash');
const { readJson } = require('../utilities');
const { languages } = require('../../js/regions');

class FestivalsUpdater extends Updater {
    constructor(region) {
        super({
            name: `Festivals ${region}`,
            filename: 'festivals.json',
            request: (splatnet) => splatnet.getCombinedFestivals(),
            imagePaths: [
                '$..images.alpha',
                '$..images.bravo',
                '$..images.panel',
                '$..special_stage.image',
            ],
            localization: [
                {
                    name: 'festivals',
                    entities: '$.festivals[*]',
                    id: 'festival_id',
                    values: 'names',
                },
                {
                    name: 'stages',
                    entities: '$..special_stage',
                    id: 'id',
                    values: 'name',
                },
            ],
        });

        this.region = region;
    }

    processData(regionData) {
        // Load existing data since we only need to modify this region's data
        let data = {};
        let filename = this.getFilename();
        if (fs.existsSync(filename))
            data = readJson(filename);

        let region = this.region.toLowerCase();
        data[region] = regionData;

        return data;
    }

    getLanguages() {
        // Return all languages for this region
        return _.filter(languages, { region: this.region });
    }
}

module.exports = FestivalsUpdater;

@@ -146,24 +146,62 @@
 ('lodash');%0A
+const jsonpath = require('jsonpath');%0A
 const %7B read
@@ -1214,24 +1214,705 @@
 gionData) %7B%0A
+        // Fix alpha/bravo images for the Chicken vs. Egg Splatfest.%0A        // For some reason these got swapped out with images that have an opaque background%0A        // even though they started out with transparent images.%0A        jsonpath.apply(regionData, '$..images.alpha', value =%3E value.replace(%0A            %22/images/festival/a070cc6b405b4fb335992d824097acd8.png%22,%0A            %22/images/festival/06b3b0b7773d9e6c4ac0a5cc5371fc32.png%22%0A        ));%0A        jsonpath.apply(regionData, '$..images.bravo', value =%3E value.replace(%0A            %22/images/festival/00e4c5fdccd3720d07127084fc1f4152.png%22,%0A            %22/images/festival/d93df77468714c6211e9377f39a559f4.png%22%0A        ));%0A%0A
         // L

Fix Chicken vs. Egg Splatfest images