/**
 * A legacy, or parents and grandparents.
 * Defined as an applicative over generic types to reduce the API surface.
 * @see mapLegacy
 */
export interface Legacy<T> {
	p1: T;
	s11: T;
	s12: T;
	p2: T;
	s21: T;
	s22: T;
}

/**
 * Applicative fmap for legacies.
 * @param l Input legacy
 * @param f Mapping function
 * @returns Transformed legacy
 */
export function mapLegacy<U, V>(l: Legacy<U>, f: (u: U) => V): Legacy<V> {
	return {
		p1: f(l.p1),
		s11: f(l.s11),
		s12: f(l.s12),
		p2: f(l.p2),
		s21: f(l.s21),
		s22: f(l.s22),
	};
}

/**
 * A veteran, or the result of a completed career.
 */
export interface Veteran {
	uma: number;
	sparks: number[];
	saddles: number[];
}

// function findUma(umas: Uma[], u: number): Uma | null {
// 	return umas.find((v) => v.chara_card_id === u) ?? null;
// }

/**
 * Compute individual affinities for a legacy using the global region ruleset.
 * @param trainee Uma (not character) ID of the trainee Uma
 * @param legacy Legacy veterans
 * @returns Individual affinities
 */
/*
export function globalAffinity(trainee: number, legacy: Legacy<Veteran>): Legacy<number> {
	const t = findUma(uma.global, trainee)?.chara_id ?? 0;
	const charas = mapLegacy(legacy, (u) => findUma(uma.global, u.uma)?.chara_id ?? 0);
	const saddles = mapLegacy(legacy, (u) => new Set(u.saddles));
	const aff = affinity.global;
	const pp = lookup(aff, charas.p1, charas.p2);
	const s11 = lookup(aff, t, charas.p1, charas.s11) + saddles.p1.intersection(saddles.s11).size;
	const s12 = lookup(aff, t, charas.p1, charas.s12) + saddles.p1.intersection(saddles.s12).size;
	const s21 = lookup(aff, t, charas.p2, charas.s21) + saddles.p2.intersection(saddles.s21).size;
	const s22 = lookup(aff, t, charas.p2, charas.s22) + saddles.p2.intersection(saddles.s22).size;
	return {
		p1: lookup(aff, t, charas.p1) + pp + s11 + s12,
		s11,
		s12,
		p2: lookup(aff, t, charas.p2) + pp + s21 + s22,
		s21,
		s22,
	};
}
*/
