/**
 * @param {App.Entity.SlaveState} slave
 * @returns {string} Slave's brand. Slave is the slave in question, but call the body part without modifiers. Rather than using "left breast" and "right breast" just use "breast". The function will then describe any brands on the breasts, if present, in natural language.
 */
App.Desc.brand = function(slave, surface) {
	"use strict";
	let r = ``;
	const bellyAccessory = slave.bellyAccessory;
	/* eslint-disable no-unused-vars*/
	const {
		he, him, his, hers, himself, boy, He, His
	} = getPronouns(slave);
	/* eslint-enable */
	if (V.showBodyMods === 1) {
		if (surface === "extra") { // Make a sentence that describes all body parts that aren't explicitly described elsewhere in longSlave. If you brand a slave on her thumb, for instance. But why.
			let extraMarks = App.Desc.extraMarks(slave, "brand");
			extraMarks = Object.keys(extraMarks);
			let length = extraMarks.length;
			if (length === 0) {
				return r;
			} else if (length === 1) {
				r += `${He} also has a single unusual brand: `;
			} else {
				r += `${He} also has several unusual brands: `;
			}

			// If L/R parts of this object match, they will be described in the same phrase. Length is used only to calculate punctuation, so we prepare to skip.
			for (const bodyPart of extraMarks) {
				if (bodyPart.startsWith("left ")) {
					let right = "right " + bodyPart.replace("left ", "");
					if (slave.brand[bodyPart] && slave.brand[right]) {
						length--;
					}
				}
			}
			let counter = 0;
			for (const bodyPart of extraMarks) {
				counter++;
				surface = App.Desc.oppositeSides(bodyPart);
				if (slave.brand[surface.center]) { // center defined, body part has no mirror.
					r += `${slave.brand[surface.center]} branded into the flesh of ${his} ${surface.center}`;
				} else { // Center not defined, body part has a mirror.
					if (!slave.brand[surface.left] && !slave.brand[surface.right]) {
						// no marks
					} else if (bodyPart.startsWith("right ") && slave.brand[surface.left]) {
						// we already described it on the left
					} else if (slave.brand[surface.left] === slave.brand[surface.right]) {
						// matching places and marks
						// note that the slave.brand object won't have slave.brand["upper armS"] with an S defined, just the left and right, so we just use the left since we know they match.
						r += `${slave.brand[surface.left]} branded into the flesh of both ${his} ${surface.both}`;
					} else if (slave.brand[surface.left] && slave.brand[surface.right]) {
						// matching places but different marks
						r += `both ${slave.brand[surface.left]} branded into the flesh of ${his} ${surface.left}, and ${slave.brand[surface.right]} branded into ${his} ${surface.right}`;
					} else if (slave.brand[surface.left]) {
						// left
						r += `${slave.brand[surface.left]} branded into the flesh of ${his} ${surface.left}`;
					} else if (slave.brand[surface.right]) {
						// right
						r += `${slave.brand[surface.right]} branded into the flesh of ${his} ${surface.right}`;
					}
				}
				if (counter === length) {
					r += `. `;
				} else if (counter === length - 1) {
					r += `, and `;
				} else if (counter < length) {
					r += `, `;
				}
			}
		} else if (surface) { /* describes a single branded body part */
			if (surface === "belly" && setup.fakeBellies.includes(bellyAccessory) && slave.brand.belly) {
				r += `${His} fake belly has the same brand, ${slave.brand.belly}, as ${his} real one. `;
			} else {
				surface = App.Desc.oppositeSides(surface);
				if (slave.brand[surface.center]) { // center defined, body part has no mirror.
					r += `${He} has ${slave.brand[surface.center]} branded into the flesh of ${his} ${surface.center}. `;
				} else { // Center not defined, body part has a mirror.
					if (!slave.brand[surface.left] && !slave.brand[surface.right]) {
						// no marks
					} else if (slave.brand[surface.left] === slave.brand[surface.right]) {
						// matching places and marks
						// note that the slave.brand object won't have slave.brand["upper armS"] with an S defined, just the left and right, so we just use the left since we know they match.
						r += `${He} has ${slave.brand[surface.left]} branded into the flesh of both ${his} ${surface.both}. `;
					} else if (slave.brand[surface.left] && slave.brand[surface.right]) {
						// matching places but different marks
						r += `${He} has both ${slave.brand[surface.left]} branded into the flesh of ${his} ${surface.left}, and ${slave.brand[surface.right]} branded into ${his} ${surface.right}. `;
					} else if (slave.brand[surface.left]) {
						// left
						r += `${He} has ${slave.brand[surface.left]} branded into the flesh of ${his} ${surface.left}. `;
					} else if (slave.brand[surface.right]) {
						// right
						r += `${He} has ${slave.brand[surface.right]} branded into the flesh of ${his} ${surface.right}. `;
					}
				}
			}
		} else { /* describes all branded body parts */
			for (let [key, value] of Object.entries(slave.brand)) {
				if (r === ``) {
					r += `${He} has `;
				}
				if (key === "belly" && setup.fakeBellies.includes(bellyAccessory) && slave.brand.belly) {
					r += `${value} branded on both ${his} real belly and ${his} fake one, `;
				} else {
					r += `${value} branded into the flesh of ${his} ${key}, `;
				}
			}
			if (r !== ``) {
				r += `marking ${him} as yours. `;
			} else {
				r += `${His} body is unmarked by brands. `;
			}
		}
	}
	return r;
};

src/npc/descriptions/describeBrands.js