App.SlaveAssignment.guardYou = (function() {
	"use strict";

	let r;

	// eslint-disable-next-line no-unused-vars
	let he, him, his, hers, himself, girl, He, His;

	let BGImpressiveness;

	// Used for selecting a successor
	let successorCandidates;
	let combatSkilled;
	let flawedTrainee;
	let candidate;

	return saGuardYou;

	/**
	 * @param {App.Entity.SlaveState} slave
	 * @returns {string}
	 */
	function saGuardYou(slave) {
		r = [];

		({
			// eslint-disable-next-line no-unused-vars
			he, him, his, hers, himself, girl, He, His
		} = getPronouns(slave));

		BGImpressiveness = Deadliness(slave);

		updateBGState(slave);
		jobPreface(slave);
		publicImpression(slave);
		jobEffects(slave);
		if (V.bodyguardTrains === 1) {
			trainReplacements(slave);
		}

		return r.join(" ");
	}

	/**
	 * @param {App.Entity.SlaveState} slave
	 *
	 */
	function jobPreface(slave) {
		r.push(`carries arms in your defense.`);
	}

	/**
	 * @param {App.Entity.SlaveState} slave
	 *
	 */
	function updateBGState(slave) {
		if (V.dojo > 1) {
			slave.rules.living = "luxurious";
		}
	}

	/**
	 * @param {App.Entity.SlaveState} slave
	 *
	 */
	function publicImpression(slave) {
		if (slave.skill.combat > 0) {
			r.push(`${His} combat skills greatly increase ${his} deadliness.`);
		}

		if (setup.bodyguardCareers.includes(slave.career)) {
			r.push(`${He} has experience in personal defense from before ${he} was a slave.`);
		} else if (slave.skill.bodyguard >= V.masteredXP) {
			r.push(`${He} has experience in personal defense from working for you.`);
		} else {
			slave.skill.bodyguard += jsRandom(1, Math.ceil((slave.intelligence + slave.intelligenceImplant) / 15) + 8);
		}

		if (slave.muscles > 30 && slave.muscles <= 95) {
			r.push(`${He} is strong and powerful, yet quick and flexible.`);
		} else if (slave.muscles > 95 && slave.height >= 185) {
			r.push(`${His} huge muscles are an intimidating sight and, despite their massive size, ${he} is tall enough to use them effectively.`);
		} else if (slave.muscles > 95) {
			r.push(`${His} huge muscles are an intimidating sight, but are so big that they actually detract from ${his} combat effectiveness.`);
		} else if (slave.muscles > 5) {
			r.push(`${He} is reasonably fit, but not enough to significantly affect ${his} combat effectiveness.`);
		} else if (slave.muscles < -95) {
			r.push(`${He} can barely stand, let alone fight. A single shot from ${his} own weapon is liable to incapacitate ${him}, making ${him} an absolute travesty of a bodyguard.`);
		} else if (slave.muscles < -30) {
			r.push(`${He} tires from just standing, rendering ${him} both ineffective and embarrassing to have as your guard.`);
		} else if (slave.muscles < -5) {
			r.push(`${He} is rather unfit, enough to negatively impact ${his} combat effectiveness.`);
		}

		if (getLimbCount(slave, 6) > 1) {
			r.push(`The artificial muscles of ${his} cybernetic limbs increase ${his} strength and flexibility to enhance ${his} combat abilities and give ${him} the intimidating appearance of a super-soldier.`);
		} else if (getLimbCount(slave, 105) > 1) {
			r.push(`${His} tough combat limbs make ${him} an intimidating sight to behold.`);
		}

		if (slave.height >= 170) {
			r.push(`${His} height gives ${him} a reach advantage with ${his} sword.`);
		}

		if (slave.health.condition > 50) {
			r.push(`${His} shining health makes ${him} a better combatant.`);
		}

		if (slave.boobs > 4000) {
			r.push(`${His} titanic tits are a terrible hindrance in actual fighting.`);
		} else if (slave.boobs > 2000) {
			r.push(`${His} big breasts get in ${his} way and reduce ${his} efficiency.`);
		}

		if (slave.dick >= 10) {
			r.push(`${His} massive dick gets in ${his} way and reduces ${his} efficiency.`);
		}

		if (slave.balls >= 15) {
			r.push(`${His} massive balls slow ${him} down and limit ${his} range of motion.`);
		}

		if (slave.butt > 6) {
			r.push(`${His} massive ass slows ${him} down and limits ${his} range of motion.`);
		}

		if (slave.hips > 2) {
			r.push(`${He} struggles to move with ${his} inhumanly wide hips and frequently gets caught between things trying to follow you.`);
		}

		if (slave.weight > 190) {
			r.push(`${His} extreme weight nearly immobilizes ${him}. ${He} struggles to move let alone protect you. At least ${his} bloated body will likely stop bullets and block doorways when needed.`);
		} else if (slave.weight > 160) {
			r.push(`${His} extreme weight limits ${his} mobility and range of motion, making ${him} a poor bodyguard but decent meatshield.`);
		} else if (slave.weight > 130) {
			r.push(`${His} extreme weight is an impediment as a bodyguard.`);
		} else if (slave.weight > 30) {
			r.push(`${His} heavy weight is an impediment as a bodyguard.`);
		} else if (slave.weight < -10) {
			r.push(`${His} light weight is an impediment as a bodyguard.`);
		}

		if (slave.health.condition < -50) {
			r.push(`${His} poor health makes ${him} a weaker combatant.`);
		}

		if (slave.health.tired > 90) {
			r.push(`${He} is exhausted and can barely stay awake, let alone ready a weapon.`);
		} else if (slave.health.tired > 60) {
			r.push(`${He} is fatigued, making ${his} situational awareness and reaction time suffer.`);
		} else if (slave.health.tired > 30) {
			r.push(`${He} is tired, slightly lowering ${his} reaction time.`);
		}

		if (slave.pregKnown === 1 || slave.bellyPreg >= 1500) {
			if (slave.bellyPreg >= 750000) {
				r.push(`${His} monolithic pregnancy greatly restricts ${his} movement and renders ${him} nearly useless in combat. ${He} can barely waddle after you, and when ${he} does, finds doors and small passages don't agree with ${his} bloated figure.`);
			} else if (slave.bellyPreg >= 450000) {
				r.push(`${His} gigantic pregnancy greatly hinders ${his} movement and terribly reduces ${his} effectiveness in combat. It also limits where ${he} can follow you, as doors and small passages don't agree with ${his} bloated figure.`);
			} else if (slave.bellyPreg >= 300000) {
				r.push(`${His} massive pregnancy obstructs ${his} movement and greatly hinders ${his} ability to protect you. It also limits where ${he} can follow you, as doors and small passages don't agree with ${his} bloated figure.`);
			} else if (slave.bellyPreg >= 150000) {
				r.push(`${His} giant pregnancy obstructs ${his} movement and greatly slows ${him} down. It also limits where ${he} can follow you, as ${he} has trouble waddling through crowds.`);
			} else if (slave.bellyPreg >= 100000) {
				r.push(`${His} giant belly gets in ${his} way and weighs ${him} down.`);
			} else if (slave.bellyPreg >= 10000) {
				r.push(`${His} huge belly is unwieldy and hinders ${him}.`);
			} else if (slave.bellyPreg >= 5000) {
				r.push(`${His} advanced pregnancy limits ${his} effectiveness.`);
			} else if (slave.bellyPreg >= 1500) {
				r.push(`${His} growing pregnancy occasionally distracts ${him} from ${his} job.`);
			} else {
				r.push(`The life just beginning to grow inside ${him} occasionally distracts ${him} from ${his} job.`);
			}
		} else if (slave.bellyImplant >= 1500) {
			if (slave.bellyImplant >= 750000) {
				r.push(`${His} monolithic, ${slave.bellyImplant}cc implant filled belly greatly restricts ${his} movement and renders ${him} nearly useless in combat. ${He} can barely waddle after you, and when ${he} does, finds doors and small passages don't agree with ${his} bloated figure.`);
			} else if (slave.bellyImplant >= 450000) {
				r.push(`${His} gigantic, ${slave.bellyImplant}cc implant filled belly greatly hinders ${his} movement and terribly reduces ${his} effectiveness in combat. It also limits where ${he} can follow you, as doors and small passages don't agree with ${his} bloated figure.`);
			} else if (slave.bellyImplant >= 300000) {
				r.push(`${His} massive, ${slave.bellyImplant}cc implant filled belly obstructs ${his} movement and greatly hinders ${his} ability to protect you. It also limits where ${he} can follow you, as doors and small passages don't agree with ${his} bloated figure.`);
			} else if (slave.bellyImplant >= 150000) {
				r.push(`${His} giant, ${slave.bellyImplant}cc implant filled belly obstructs ${his} movement and greatly slows ${him} down. It also limits where ${he} can follow you, as ${he} has trouble waddling through crowds.`);
			} else if (slave.bellyImplant >= 100000) {
				r.push(`${His} giant, ${slave.bellyImplant}cc implant filled belly is very heavy and unwieldy, frequently getting in the way of ${his} job.`);
			} else if (slave.bellyImplant >= 10000) {
				r.push(`${His} huge, ${slave.bellyImplant}cc implant filled belly is very heavy and unwieldy, throwing off ${his} weight and making ${him} far less effective.`);
			} else if (slave.bellyImplant >= 5000) {
				r.push(`${His} large, ${slave.bellyImplant}cc implant filled belly is heavy and unwieldy, limiting ${his} effectiveness.`);
			} else if (slave.bellyImplant >= 1500) {
				r.push(`${His} swollen, ${slave.bellyImplant}cc implant filled belly is heavy and occasionally distracts ${him}.`);
			}
		}
		if (slave.labor === 1) {
			r.push(`${He}'s feeling labor pains, greatly detracting from ${his} ability to protect you.`);
		} else if (slave.preg >= slave.pregData.normalBirth && slave.pregControl !== "labor suppressors") {
			r.push(`${He}'ll be going into labor any time now, detracting from ${his} ability to protect you.`);
		}

		if (slave.bellyFluid >= 10000) {
			r.push(`${His} hugely bloated, ${slave.inflationType}-filled belly is taut and painful, hindering ${his} ability to guard you.`);
		} else if (slave.bellyFluid >= 5000) {
			r.push(`${His} bloated, ${slave.inflationType}-stuffed belly is constantly jiggling and moving, distracting ${him} and throwing off ${his} weight.`);
		} else if (slave.bellyFluid >= 2000) {
			r.push(`${His} distended, ${slave.inflationType}-belly is uncomfortable and heavy, distracting ${him}.`);
		}

		if (slave.teeth === "pointy") {
			r.push(`${His} sharp teeth add nothing to ${his} actual effectiveness, but they're certainly intimidating.`);
		}

		if ((slave.skill.combat < 1) && (jsRandom(-100, 150) <= (slave.intelligence + slave.intelligenceImplant))) {
			r.push(`After some experience guarding you, and diligent practice in the armory, <span class="green">${his} combat skills increase.</span>`);
			slave.skill.combat += 1;
		} else if (slave.skill.combat >= 1) {
			r.push(`${He} maintains ${his} combat skill with practice in the armory.`);
		} else {
			r.push(`Though ${he} practices diligently, ${his} basic combat skills do not impress.`);
		}

		r.push(`${His} constant presence is`);
		if (BGImpressiveness > 6) {
			r.push(`extremely intimidating, <span class="green">adding much to your reputation.</span>`);
			if (slave.career === "an arcology owner") {
				r.push(`You've made a one-time rival arcology owner into a deadly and loyal protector, a feat of slaveownership that's <span class="green">internationally famous.</span>`);
				repX(BGImpressiveness * 50, "bodyguard", slave);
			}
		} else if (BGImpressiveness > 3) {
			r.push(`intimidating, <span class="green">adding to your reputation.</span>`);
		} else {
			r.push(`hardly intimidating, <span class="yellow">barely adding to your reputation.</span>`);
		}

		repX(BGImpressiveness * 50, "bodyguard", slave);
	}

	/**
	 * @param {App.Entity.SlaveState} slave
	 *
	 */
	function jobEffects(slave) {
		r.push(`Being continually trusted with your life <span class="hotpink"> increases ${his} devotion to you</span> and encourages ${him} to <span class="mediumaquamarine"> trust you in turn.</span>`);
		slave.devotion += 2;
		slave.trust += 4;

		if (V.dojo > 1) {
			r.push(`${He} <span class="hotpink">appreciates</span> how special it is that ${he} has a nice room off the armory to rest in. ${He} can finally <span class="green">rest easy</span> while still keeping tabs on your safety.`);
			slave.devotion += 1;
		} else {
			r.push(`Between protecting you, training, and keeping vigil while you sleep, ${he} lives a <span class="red">very tiring</span> life.`);
		}
		tired(slave);
	}

	/**
	 * @param {App.Entity.SlaveState} slave
	 *
	 */
	function trainReplacements(slave) {
		if (slave.devotion > 95 && slave.trust > 50 && slave.skill.combat > 0 && slave.intelligence + slave.intelligenceImplant > 15) {
			successorCandidates = V.slaves.filter(function(s) { return (assignmentVisible(s) || s.assignment === Job.CONCUBINE || s.assignment === Job.WARDEN || s.assignment === Job.HEADGIRL || s.assignment === Job.QUARTER || s.assignment === Job.MASTERSUITE) && bodyguardSuccessorEligible(s); });
			combatSkilled = successorCandidates.filter(function(s) { return s.skill.combat > 0; });

			r.push(`${He}'s confident in ${his} martial skills, but smart enough to know that ${he} isn't immortal, and devoted enough to worry about who will protect you should ${he} die.`);
			if (combatSkilled.length < 2) {
				flawedTrainee = 0;
				if (slave.relationship > 1) {
					candidate = getSlave(slave.relationshipTarget);
					if (candidate !== undefined && candidate.skill.combat === 0 && bodyguardSuccessorEligible(candidate)) {
						const candidatePronouns = getPronouns(candidate);
						r.push(`${He} does ${his} best to train ${candidate.slaveName} whenever ${he} can, hoping that ${his}`);
						if (slave.relationship > 4) {
							r.push(`${candidatePronouns.wife}`);
						} else if (slave.relationship === 4) {
							r.push(`lover`);
						} else if (slave.relationship === 3) {
							r.push(`${candidatePronouns.girl} friend`);
						} else {
							r.push(`best friend`);
						}
						r.push(`can be made capable of stepping into ${his} place.`);
					}
				}
				if (!candidate) {
					if (V.HeadGirl !== 0 && V.HeadGirl.skill.combat === 0 && bodyguardSuccessorEligible(V.HeadGirl)) {
						r.push(`${He} does ${his} best to train ${V.HeadGirl.slaveName} whenever ${he} can, hoping that your Head Girl can be made capable of stepping into ${his} place.`);
						candidate = V.HeadGirl;
					}
				}
				if (!candidate) {
					if (V.Concubine !== 0 && V.Concubine.skill.combat === 0 && V.Concubine.devotion > 50 && V.Concubine.muscles >= -30 && V.Concubine.weight < 150 && V.Concubine.butt < 10 && V.Concubine.boobs < 25000 && V.Concubine.belly < 5000 && V.Concubine.balls < 20 && V.Concubine.dick < 15 && V.Concubine.fuckdoll === 0 && V.Concubine.fetish !== "mindbroken" && canWalk(V.Concubine)) {
						r.push(`${He} does ${his} best to train ${V.Concubine.slaveName} whenever ${he} can, hoping that your Concubine can be made capable of stepping into ${his} place.`);
						if (V.Concubine.boobs >= 8000 || V.Concubine.butt >= 10 || V.Concubine.belly >= 5000 || V.Concubine.balls >= 10 || V.Concubine.dick >= 10 || V.Concubine.muscles < 0 || V.Concubine.weight >= 100) {
							r.push(`${His} body is poorly suited for combat, but ${he} can learn to work around it with enough effort.`);
							flawedTrainee = jsRandom(0, 50);
						}
						candidate = V.Concubine;
					}
				}
				if (!candidate) {
					if (V.Wardeness !== 0 && V.Wardeness.skill.combat === 0 && V.Wardeness.fetish !== "mindbroken" && bodyguardSuccessorEligible(V.Wardeness)) {
						r.push(`${He} does ${his} best to train ${V.Wardeness.slaveName} whenever ${he} can, hoping that your Wardeness can be made capable of stepping into ${his} place.`);
						candidate = V.Wardeness;
					}
				}
				if (!candidate) {
					candidate = successorCandidates.find(function(s) { return s.skill.combat === 0; });
					if (candidate) {
						r.push(`${He} does ${his} best to train ${candidate.slaveName} whenever ${he} can, hoping that ${his} subordinate can be made capable of stepping into ${his} place.`);
					}
				}
				if (candidate) {
					if ((slave.intelligence + slave.intelligenceImplant - flawedTrainee) > jsRandom(1, 500)) {
						r.push(`By the end of the week, ${he} is satisfied that ${candidate.slaveName} <span class="green">has the combat skill</span> to contribute to your defense.`);
						V.slaves[V.slaveIndices[candidate.ID]].skill.combat = 1;
					}
				} else {
					r.push(`${He} finds no suitable candidates to serve as ${his} replacement, leaving ${him} stressed over your future safety. The worry is <span class="red">exhausting</span> and <span class="red">bad for ${his} health.</span>`);
					healthDamage(slave, 3);
					slave.health.tired += 15;
				}
			} else {
				r.push(`${He} takes care to look after the skills of your other defensively capable slaves, satisfied that there are enough of them living in your penthouse.`);
			}
		}
	}
})();

src/endWeek/saGuardYou.js