using UnityEngine;
[CreateAssetMenu(menuName = "Actions/Block")]
public class BlockAction : EnemyAction
{
    public override float CalculateUtility(EnemyDecisionContext ctx)
    {
        if (!ctx.Entity.Brain.Combat.CanBlock()) return 0f;
        
        float healthFactor = Mathf.InverseLerp(ctx.Entity.health.GetMaxHealth(), 0, ctx.Entity.health.CurrentHealth);
        healthFactor = Mathf.Clamp01(healthFactor);
        //float attackCooldownFactor = CanAttack ? 0.2f : 0f; //MAYBE USE IT LATER ON
        float roleBias = (ctx.CurrentRole == EnemyRole.Attack) ? 0.1f : 0f;
        float distanceScore = Mathf.InverseLerp(ctx.Config.engageDistance * 1.5f, 0f, ctx.DistanceToPlayer);
        
        float baseDesire = 0.1f;

        float utility = baseDesire +
                        healthFactor * 0.4f +
                        distanceScore * 0.4f +
                        roleBias;
        return Mathf.Clamp01(utility);
    }

    public override void Execute(EnemyBrain brain, EnemyDecisionContext ctx)
    {
        brain.Combat.Block();
    }
}
