package com.bernard.greposimu.engine.game;

import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;

import com.bernard.greposimu.model.FightStats;
import com.bernard.greposimu.model.game.GameConfig;
import com.bernard.greposimu.model.game.units.Hero;
import com.bernard.greposimu.model.game.units.Unit;

public class Heroes {
	
	/**
	 * Compute the bonus applied to each unit
	 * @param hero The hero object to consider
	 * @param level The level of the hero
	 * @param off true for the off stat, false for the def stat
	 * @return For each unit, the bonus that should be applied to it
	 */
	public static Map<Unit, FightStats> heroFightBonuses(GameConfig gc, Hero hero, int level, boolean off){
		
		if(hero == null)
			return new HashMap<>();
		
		Map<String,FightStats> bonuses = new HashMap<>();
		
		double bonus = hero.getPowerBaseValue() + level * hero.getPowerValuePerLevel();
		
		FightStats appliedBonus = null;
		switch(hero.getId()) {
		case "agamemnon":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("hoplite", appliedBonus);
			bonuses.put("archer", appliedBonus);
			break;
		case "ajax":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("hoplites", appliedBonus);
			break;
		case "alexandrios":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("archers", appliedBonus);
			break;
		case "deimos":
			appliedBonus = FightStats.cst(bonus);
			if(off)
				for(Unit u : gc.getUnits())bonuses.put(u.getId(),appliedBonus);
			break;
		case "hector":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("sword", appliedBonus);
			bonuses.put("slinger", appliedBonus);
			break;
		case "lysippe":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("rider", appliedBonus);
			break;
		case "leonidas":
			appliedBonus = FightStats.terrestre(bonus);
			if(!off)
				for(Unit u : gc.getUnits())bonuses.put(u.getId(),appliedBonus);
			break;
		case "mihalis":
			appliedBonus = new FightStats(bonus, bonus, 0.0, 0.0);
			for(Unit u : gc.getUnits())bonuses.put(u.getId(),appliedBonus);
			break;
		case "medea":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("slinger", appliedBonus);
			break;
		case "melousa":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("chariot", appliedBonus);
			break;
		case "pelops":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("hoplite", appliedBonus);
			bonuses.put("chariot", appliedBonus);
			break;
		case "themistokles":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("godsent", appliedBonus);
			bonuses.put("rider", appliedBonus);
			break;
		case "telemachos":
			appliedBonus = FightStats.terrestre(bonus);
			bonuses.put("sword", appliedBonus);
			break;
		case "urephon":
			appliedBonus = FightStats.terrestre(bonus);
			for(Unit u : gc.getUnits())if(u.isMythological())bonuses.put(u.getId(),appliedBonus);
			break;
		case "zuretha":
			appliedBonus = new FightStats(0.0, 0.0, 0.0, bonus);
			for(Unit u : gc.getUnits())bonuses.put(u.getId(),appliedBonus);
			break;
		default:
			// No buff
			break;
		}
		return bonuses.keySet().stream().collect(Collectors.toMap(k -> gc.getUnit(k), k -> bonuses.get(k)));
	}
	
}
