'use strict';

const assert = require('./../../assert');
const common = require('./../../common');

let battle;

describe('Storm Drain', () => {
	afterEach(() => {
		battle.destroy();
	});

	it('should grant immunity to Water-type moves and boost Special Attack by 1 stage', () => {
		battle = common.createBattle([[
			{ species: 'Gastrodon', ability: 'stormdrain', moves: ['sleeptalk'] },
		], [
			{ species: 'Azumarill', ability: 'thickfat', moves: ['aquajet'] },
		]]);
		battle.makeChoices('move sleeptalk', 'move aquajet');
		assert.fullHP(battle.p1.active[0]);
		assert.statStage(battle.p1.active[0], 'spa', 1);
	});

	it('should redirect Max Geyser', () => {
		battle = common.gen(8).createBattle({ gameType: 'doubles' }, [[
			{ species: 'Gastrodon', ability: 'stormdrain', moves: ['sleep talk'] },
			{ species: 'Manaphy', ability: 'hydration', moves: ['scald'] },
		], [
			{ species: 'Igglybuff', ability: 'cute charm', moves: ['sleep talk'] },
			{ species: 'Igglybuff', ability: 'cute charm', moves: ['sleep talk'] },
		]]);
		battle.makeChoices('move sleeptalk, move scald dynamax 1', 'move sleep talk, move sleep talk');
		assert.fullHP(battle.p1.active[0]);
		assert.statStage(battle.p1.active[0], 'spa', 1);
	});

	it('should redirect single-target Water-type attacks to the user if it is a valid target', () => {
		battle = common.gen(5).createBattle({ gameType: 'triples' }, [[
			{ species: 'Gastrodon', ability: 'stormdrain', moves: ['sleeptalk'] },
			{ species: 'Azumarill', ability: 'thickfat', moves: ['aquajet'] },
			{ species: 'Azumarill', ability: 'thickfat', moves: ['aquajet'] },
		], [
			{ species: 'Azumarill', ability: 'thickfat', moves: ['aquajet'] },
			{ species: 'Azumarill', ability: 'thickfat', moves: ['aquajet'] },
			{ species: 'Azumarill', ability: 'thickfat', moves: ['aquajet'] },
		]]);
		battle.makeChoices('move sleeptalk, move aquajet 1, move aquajet 1', 'move aquajet 3, move aquajet 3, move aquajet 2');
		assert.statStage(battle.p1.active[0], 'spa', 3);
		assert.false.fullHP(battle.p1.active[2]);
		assert.false.fullHP(battle.p2.active[0]);
	});

	it('should redirect to the fastest Pokemon with the ability', () => {
		battle = common.createBattle({ gameType: 'doubles' }, [[
			{ species: 'Gastrodon', ability: 'stormdrain', moves: ['sleeptalk'] },
			{ species: 'Gastrodon', ability: 'stormdrain', moves: ['sleeptalk'] },
		], [
			{ species: 'Azumarill', ability: 'thickfat', moves: ['waterfall'] },
			{ species: 'Azumarill', ability: 'thickfat', moves: ['waterfall'] },
		]]);
		const [fastGastrodon, slowGastrodon] = battle.p1.active;
		fastGastrodon.boostBy({ spe: 6 });
		battle.makeChoices('move sleeptalk, move sleeptalk', 'move waterfall 1, move waterfall 2');
		assert.statStage(fastGastrodon, 'spa', 2);
		assert.statStage(slowGastrodon, 'spa', 0);
	});

	it('should not redirect if another Pokemon has used Follow Me', () => {
		battle = common.createBattle({ gameType: 'doubles' }, [[
			{ species: 'Gastrodon', ability: 'stormdrain', moves: ['sleeptalk'] },
			{ species: 'Azumarill', ability: 'thickfat', moves: ['followme'] },
		], [
			{ species: 'Azumarill', ability: 'thickfat', moves: ['aquajet'] },
			{ species: 'Azumarill', ability: 'thickfat', moves: ['aquajet'] },
		]]);
		const [stormDrainMon, defender] = battle.p1.active;
		battle.makeChoices('move sleeptalk, move followme', 'move aquajet 2, move aquajet 1');
		assert.statStage(stormDrainMon, 'spa', 0);
		assert.false.fullHP(defender);
	});

	it('should have its Water-type immunity and its ability to redirect moves suppressed by Mold Breaker', () => {
		battle = common.createBattle({ gameType: 'doubles' }, [[
			{ species: 'Gastrodon', ability: 'stormdrain', moves: ['endure'] },
			{ species: 'Manaphy', ability: 'hydration', moves: ['tailglow'] },
		], [
			{ species: 'Haxorus', ability: 'moldbreaker', moves: ['waterfall'] },
			{ species: 'Reshiram', ability: 'turboblaze', moves: ['waterpulse'] },
		]]);
		const [stormDrainMon, ally] = battle.p1.active;
		battle.makeChoices('move endure, move tailglow', 'move waterfall 1, move waterpulse 2');
		assert.false.fullHP(stormDrainMon);
		assert.false.fullHP(ally);
	});
});
