using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

namespace RebootKit.Engine.Foundation {
    public interface IPredicate {
        bool Evaluate();
    }

    [Serializable]
    public class PredicateAnd : IPredicate {
        [SerializeReference] List<IPredicate> m_Rules;

        public PredicateAnd(IEnumerable<IPredicate> rules) {
            m_Rules = new List<IPredicate>(rules);
        }

        public bool Evaluate() {
            return m_Rules.All(t => t.Evaluate());
        }
    }
    
    [Serializable]
    public class PredicateOr : IPredicate {
        [SerializeReference] List<IPredicate> m_Rules;

        public PredicateOr(IEnumerable<IPredicate> rules) {
            m_Rules = new List<IPredicate>(rules);
        }

        public bool Evaluate() {
            return m_Rules.Any(t => t.Evaluate());
        }
    }

    [Serializable]
    public class PredicateConsts : IPredicate {
        bool m_Result;

        public PredicateConsts(bool result) {
            m_Result = result;
        }

        public bool Evaluate() => m_Result;
    }
}