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

namespace SCE
{
    public static class BestialityUtility
    {
        public static List<PreceptDef> proBestialityPrecepts = new() {
            SCEPreceptDefOf.Bestiality_Approved,
            SCEPreceptDefOf.Bestiality_NoVenerated,
            SCEPreceptDefOf.Bestiality_VeneratedOnly, 
            SCEPreceptDefOf.Bestiality_Revered,
        };

        public static bool IsProBestiality(this Ideo ideo) => proBestialityPrecepts.Any(p => ideo.HasPrecept(p));

        public static bool ToleratesSexWithAnimal(this Ideo ideo, ThingDef animal)
        {
            return ideo.HasPrecept(SCEPreceptDefOf.Bestiality_DontCare) || ideo.ApprovesSexWithAnimal(animal);
        }

        public static bool ApprovesSexWithAnimal(this Ideo ideo, ThingDef animal)
        {
            return ideo.IsProBestiality() && !ideo.SelectivelyForbidsSexWithAnimal(animal);            
        }

        public static bool SelectivelyForbidsSexWithAnimal(this Ideo ideo, ThingDef animal)
        {
            if (ideo.HasPrecept(SCEPreceptDefOf.Bestiality_VeneratedOnly))
            {
                return !ideo.IsVeneratedAnimal(animal);
            }
            if (ideo.HasPrecept(SCEPreceptDefOf.Bestiality_NoVenerated))
            {
                return ideo.IsVeneratedAnimal(animal);
            }
            return false;
        }

        public static bool CanDoLewdAnimalWork(Pawn human, Pawn animal)
        {
            if (human.Ideo == null || !human.Ideo.HasPrecept(SCEPreceptDefOf.AnimalConnection_Lovin))
            {
                return false;
            }
            return SexAppraiser.would_fuck(human, animal) > 0;
        }
    }
}