using System.Text;
using Schema;
using UnityEngine;
using VOID.Generic.Dict;
using VOID.Generic.Objects.Unit;

namespace VOID.Generic.AI.Schema.Conditionals
{
    [DarkIcon("Conditionals/d_IsNull")]
    [LightIcon("Conditionals/IsNull")]
    [Category(SchemaCategory.ThisUnit)]
    public class IsUnitInSight : Conditional
    {
        [SerializeField] private AttitudeType _attitudeType;
        
        public override bool Evaluate(object nodeMemory, SchemaAgent agent)
        {
            return (agent as UnitObjectSchemaAgent)?.unit.unitSenses.GetUnitsInSightByAttitude(_attitudeType).Count > 0;
        }

        public override GUIContent GetConditionalContent()
        {
            var sb = new StringBuilder();
            if (invert) sb.Append("<color=red>NOT</color> ");
            sb.Append(
                $"<color=red>{nameof(UnitObjectSenses)}</color> has at least one <color=red>{_attitudeType}</color> in range");
            return new GUIContent(sb.ToString());
        }
    }
}