﻿using System.Linq;
using Verse;

namespace rjw
{
	public class Hediff_PartsSizeChangerPC : HediffWithComps
	{
		public override void PostAdd(DamageInfo? dinfo)
		{
			if (Part != null)
			{
				foreach (var sexPart in pawn.health.hediffSet.hediffs.Where(x => x.Part == Part).OfType<ISexPartHediff>().ToList())
				{
					HediffComp_SexPart partComp = sexPart.GetPartComp();
					if (partComp != null)
					{
						//Log.Message("  Hediff_PartsSizeChanger: " + hed.Label);
						//Log.Message("  Hediff_PartsSizeChanger: " + hed.Severity);
						//Log.Message("  Hediff_PartsSizeChanger: " + CompHediff.SizeBase);
						//Log.Message("  Hediff_PartsSizeChanger: " + "-----");
						//Log.Message("  Hediff_PartsSizeChanger: " + this.Label);
						//Log.Message("  Hediff_PartsSizeChanger: " + this.Severity);
						partComp.UpdateSeverity(CurStage.minSeverity);
						//Log.Message("  Hediff_PartsSizeChanger: " + "-----");
						//Log.Message("  Hediff_PartsSizeChanger: " + hed.Label);
						//Log.Message("  Hediff_PartsSizeChanger: " + hed.Severity);
						//Log.Message("  Hediff_PartsSizeChanger: " + CompHediff.SizeBase);
					}
				}
			}

			pawn.health.RemoveHediff(this);
		}
	}

	public class Hediff_PartsSizeChangerCE : HediffWithComps
	{
		public override void PostAdd(DamageInfo? dinfo)
		{
			if (Part != null)
			{
				foreach (var sexPart in pawn.health.hediffSet.hediffs.Where(x => x.Part == Part).OfType<ISexPartHediff>().ToList())
				{
					HediffComp_SexPart partComp = sexPart.GetPartComp();
					if (partComp != null)
					{
						partComp.UpdateSeverity(def.initialSeverity);
					}
				}
			}

			pawn.health.RemoveHediff(this);
		}
	}
}