using UnityEngine;

[CreateAssetMenu(menuName = "Actions/Idle")]
public class IdleAction : EnemyAction
{
    [SerializeField] private float maxApproachDistance;
    [SerializeField] private float idleRelaxTime;
    public override float CalculateUtility(EnemyDecisionContext ctx)
    {
        float distanceFactor = Mathf.InverseLerp(1f, maxApproachDistance, ctx.DistanceToPlayer);
        distanceFactor = Mathf.Clamp01(distanceFactor);
        
        float postAttackRelax = Mathf.InverseLerp(0f, idleRelaxTime, ctx.TimeSinceLastAttack);
        float roleBias = (ctx.CurrentRole == EnemyRole.Idle) ? 0.3f : 0f;
        
        float baseDesire = 0.1f;
        
        float utility = baseDesire +
                        distanceFactor * 0.5f +
                        postAttackRelax * 0.2f +
                        roleBias;

        return Mathf.Clamp01(utility);
    }

    public override void Execute(EnemyBrain brain, EnemyDecisionContext ctx)
    {
        //Debug.Log("basically do nothing, we are idling!");
        brain.animationBridge.UpdateApproachState(false);
        brain.animationBridge.UpdateIdleState(true);
    }
    
}
