using System.Collections.Generic;
using System.Linq;
using rjw.Modules.Shared.Logs;
using Verse;
using Verse.AI.Group;

namespace SCE
{
    public class Trigger_SexFinished : Trigger
    {
        public Pawn pawn = null;

        private static readonly ILog log = LogManager.GetLogger<Trigger_SexFinished, DebugLogProvider>();

        public override bool ActivateOn(Lord lord, TriggerSignal signal)
        {
            if (signal.type != TriggerSignalType.Signal)
                return false;
            
            var innerSignal = signal.signal;
            if (innerSignal.tag != SignalTags.SexFinished)
                return false;

            log.Message($"Received {SignalTags.SexFinished} signal");
            
            if (pawn == null)
                return true;

            if (innerSignal.args.TryGetArg<List<Pawn>>(SignalArgNames.Pawns, out var pawns))
            {
                log.Message($"Signal args are " + pawns.Select(p => p.Label).ToCommaList());
                return pawns.Contains(pawn);
            }

            return signal.Pawn == pawn;
        }
    }
}