import { Move } from './move';
import { Serializable } from './iserializable';

interface IUnit {
    unitName: String;
    reflect: Number;
    life: Number;
    speed: Number;
    imageUrl: String;
    affinity: String;
    moves: any[];
}

export class Unit implements Serializable<IUnit>, IUnit {

    unitName: String;
    reflect: Number;
    life: Number;
    speed: Number;
    imageUrl: String;
    affinity: String;
    moves: any[];

    deserialize(_unit: IUnit) {

        let nb = 0;

        this.unitName = _unit.unitName;
        this.imageUrl = _unit.imageUrl;
        this.affinity = _unit.affinity;

        // Rajoute des noms fictifs aux différents moves.
        if(_unit.moves != undefined)
            _unit.moves.forEach(move => {
                nb++;
                move.moveName = "Move" + nb;
            });

        this.moves = _unit.moves;

        return this;
    }
}
        this.reflect = _unit.reflect;
        this.life = _unit.life;
        this.speed = _unit.speed;