package eu.mhsl.minenet.minigames.instance.game.stateless.types.towerdefense.enemies;

import net.minestom.server.entity.EntityCreature;
import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.attribute.Attribute;

public record EnemyFactory(EntityType entityType, float health, double speed) {
    /**
     * Factory for a tower defense enemy.
     * @param entityType type of enemy
     * @param health base health (between 0 and 1024, default 10)
     * @param speed walk speed (default 0.1)
     */
    public EnemyFactory {
        if(health > 1024 || health <= 0) throw new IllegalArgumentException("Enemy health has to be between 0 and 1024");
    }

    public EnemyFactory(EntityType entityType) {
        this(entityType, 10, 0.1);
    }

    public EntityCreature buildEntity() {
        EntityCreature entity = new EntityCreature(this.entityType);
        entity.getAttribute(Attribute.MOVEMENT_SPEED).setBaseValue(this.speed);
        entity.getAttribute(Attribute.MAX_HEALTH).setBaseValue(this.health);
        entity.setHealth(this.health);
        return entity;
    }

    public int getStrength() {
        return (int) Math.floor(this.health * this.speed * 5);
    }
}
