package com.bernard.greposimu.model;

import java.util.Arrays;

import com.bernard.greposimu.model.game.units.FightType;

public class FightStats implements Cloneable{
	public double hack;
	public double pierce;
	public double distance;
	public double ship;
	
	public FightStats(double hack, double pierce, double distance, double ship) {
		this.hack = hack;
		this.pierce = pierce;
		this.distance = distance;
		this.ship = ship;
	}
	
	public static final FightStats ofType(FightType type, double value) {
		switch(type) {
		case HACK:
			return new FightStats(value, 0.0, 0.0, 0.0); 
		case PIERCE:
			return new FightStats(0.0, value, 0.0, 0.0); 
		case DISTANCE:
			return new FightStats(0.0, 0.0, value, 0.0); 
		default:
			return null;
		}
	}
	
	public static final FightStats zero() {
		return new FightStats(0, 0, 0, 0);
	}
	
	public static final FightStats one() {
		return new FightStats(1.0, 1.0, 1.0, 1.0);
	}
	
	public static final FightStats terrestre(double value) {
		return new FightStats(value, value, value, 0.0);
	}
	
	public static final FightStats naval(double value) {
		return new FightStats(0.0, 0.0, 0.0, value);
	}
	
	public static final FightStats cst(double value) {
		return new FightStats(value, value, value, value);
	}
	
	public static final FightStats add(FightStats a,FightStats b) {
		return new FightStats(a.hack + b.hack, a.pierce + b.pierce, a.distance + b.distance, a.ship + b.ship);
	}
	
	public static final FightStats add(FightStats... arr) {
		return Arrays.stream(arr).reduce(FightStats.zero(), FightStats::add);
	}
	
	public static final FightStats sub(FightStats a,FightStats b) {
		return new FightStats(a.hack - b.hack, a.pierce - b.pierce, a.distance - b.distance, a.ship - b.ship);
	}
	
	public static final FightStats mul(FightStats a,FightStats b) {
		return new FightStats(a.hack * b.hack, a.pierce * b.pierce, a.distance * b.distance, a.ship * b.ship);
	}
	
	public static final FightStats prod(int k,FightStats b) {
		return new FightStats(k * b.hack, k * b.pierce, k * b.distance, k * b.ship);
	}
	
	public double getHack() {
		return hack;
	}

	public double getPierce() {
		return pierce;
	}

	public double getDistance() {
		return distance;
	}

	public double getShip() {
		return ship;
	}

	@Override
	public FightStats clone() {
		return new FightStats(hack, pierce, distance, ship);
	}
	
	@Override
	public String toString() {
		return "(%.4f,%.4f,%.4f,%.4f)".formatted(hack,pierce,distance,ship);
	}
}
