using System.Collections.Generic;
using System.Linq;
using Verse;
using RimWorld;

namespace SCE
{
    public abstract class PreceptComp_ConditionalMemoryThought : PreceptComp_Thought
    {
        public HistoryEventDef eventDef;

        public ThoughtDef removesThought;

        public override IEnumerable<TraitRequirement> TraitsAffecting => ThoughtUtility.GetNullifyingTraits(thought);

        protected abstract Thought_Memory TryMakeMemory(HistoryEvent ev, Precept precept, Pawn member);

        public override void Notify_MemberWitnessedAction(HistoryEvent ev, Precept precept, Pawn member)
        {
            if (ev.def != eventDef)
            {
                return;
            }

            Need_Mood mood = member.needs?.mood;
            if (mood == null)
            {
                return;
            }

            var memory = TryMakeMemory(ev, precept, member);
            if (memory == null)
            {
                return;
            }

            mood.thoughts.memories.TryGainMemory(memory);

            if (removesThought != null)
            {
                mood.thoughts.memories.RemoveMemoriesOfDef(removesThought);
            }
        }
    }
}