({
    onStart(pokemon) {
        this.effectState.turnBoostedStatus = false;
        this.effectState.turnBoostedMove = false;
    },

    onBeforeTurn(pokemon) {

        this.effectState.turnBoostedStatus = false;
        this.effectState.turnBoostedMove = false;
    },

    onResidual(pokemon) {
        if (!pokemon.hp) return;
        if (!pokemon.status || !['par', 'brn', 'psn', 'tox'].includes(pokemon.status)) return;

        const stats = {
            atk: pokemon.getStat('atk', false, true),
            def: pokemon.getStat('def', false, true),
            spa: pokemon.getStat('spa', false, true),
            spd: pokemon.getStat('spd', false, true),
            spe: pokemon.getStat('spe', false, true)
        };

        let best = 'atk';
        for (const stat in stats) {
            if (stats[stat] > stats[best]) best = stat;
        }

        if (!this.effectState.turnBoostedStatus) {
            this.boost({ [best]: 1 }, pokemon);
            this.effectState.turnBoostedStatus = true;
        }
    },

    onDamagingHit(damage, target, source, move) {
        if (!['Electric', 'Fire', 'Water', 'Fairy', 'Poison'].includes(move.type)) return;

        const stats = {
            atk: target.getStat('atk', false, true),
            def: target.getStat('def', false, true),
            spa: target.getStat('spa', false, true),
            spd: target.getStat('spd', false, true),
            spe: target.getStat('spe', false, true)
        };

        let best = 'atk';
        for (const stat in stats) {
            if (stats[stat] > stats[best]) best = stat;
        }

        if (!this.effectState.turnBoostedMove) {
            this.boost({ [best]: 1 }, target);
            this.effectState.turnBoostedMove = true;
        }
    },

    flags: {
        failroleplay: 1,
        noreceiver: 1,
        noentrain: 1,
        notrace: 1,
        failskillswap: 1,
        cantsuppress: 1
    },

    name: "Flavor Profile",
    rating: 3
})
