public static void SetProtected(this NpcConfiguration.Flag Flags, bool value, bool ignoreIfEssential = true) => Flags = value == Flags.HasFlag(NpcConfiguration.Flag.Protected) || (Flags.HasFlag(NpcConfiguration.Flag.Essential) && ignoreIfEssential)? Flags : value ? (Flags & (~NpcConfiguration.Flag.Essential)) | NpcConfiguration.Flag.Essential : (Flags & (~NpcConfiguration.Flag.Protected));
        //public static List<TMajor> GetMasterAndOverrides<TMajor>(this TMajor record, SynthesisState<ISkyrimMod, ISkyrimModGetter> state) where TMajor : class, IMajorRecordCommonGetter
        //{
        //    return state.LoadOrder.SelectMany(x => x.Value.Mod?.GetTopLevelGroupGetter<TMajor>()).Where(x => x.Value.FormKey.ID == record.FormKey.ID).Select(x => x.Value).ToList();
        //}
        //public static List<TMajor> GetOverrides<TMajor>(this TMajor record, SynthesisState<ISkyrimMod, ISkyrimModGetter> state) where TMajor : class, IMajorRecordCommonGetter
        //{
        //    var order = record.GetOrder(state);
        //    return state.LoadOrder.PriorityOrder.Reverse().Skip(order+1).Select(x => x.Mod).SelectMany(x=>x?.GetTopLevelGroupGetter<TMajor>()).Where(x => x.Value.FormKey.ID == record.FormKey.ID).Select(x => x.Value).ToList();
        //}
        //public static List<TMajor> GetOverriden<TMajor>(this TMajor record, SynthesisState<ISkyrimMod, ISkyrimModGetter> state) where TMajor : class, IMajorRecordCommonGetter
        //{
        //    var order = record.GetOrder(state);
        //    return state.LoadOrder.PriorityOrder.Reverse().Take(order).Select(x => x.Mod).SelectMany(x => x?.GetTopLevelGroupGetter<TMajor>()).Where(x => x.Value.FormKey.ID == record.FormKey.ID).Select(x => x.Value).ToList();
        //}
        //public static TMajor GetMaster<TMajor>(this TMajor record, SynthesisState<ISkyrimMod, ISkyrimModGetter> state) where TMajor : class, IMajorRecordCommonGetter
        //{
        //    return state.LoadOrder.PriorityOrder.Reverse().Select(x => x.Mod).SelectMany(x=>x?.GetTopLevelGroupGetter<TMajor>()).Where(x => x.Value.FormKey.ID == record.FormKey.ID).Select(x => x.Value).First();
        //}
        //public static TMajor? GetFromFile<TMajor>(this TMajor record, string FileName, SynthesisState<ISkyrimMod, ISkyrimModGetter> state) where TMajor : class, IMajorRecordCommonGetter
        //{
        //    return state?.LoadOrder?.GetModByFileName(FileName)?.GetTopLevelGroupGetter<TMajor>().Where(x => x.Value.FormKey.ID == record.FormKey.ID).FirstOrDefault()?.Value;
        //}
        //public static TMajor? GetFromMod<TMajor>(this TMajor record, ISkyrimModGetter? Mod) where TMajor : class, IMajorRecordCommonGetter
        //{
        //    return Mod?.GetTopLevelGroupGetter<TMajor>().Where(x => x.Value.FormKey.ID == record.FormKey.ID).FirstOrDefault()?.Value;
        //}


        public static void SetEssential(this NpcConfiguration.Flag Flags, bool value) => Flags = value == Flags.HasFlag(NpcConfiguration.Flag.Essential)?Flags: value ? (Flags & (~NpcConfiguration.Flag.Protected)) | NpcConfiguration.Flag.Essential : (Flags & (~NpcConfiguration.Flag.Essential));