import { BooleanField } from "@league-of-foundry-developers/foundry-vtt-types/src/foundry/common/data/fields.mjs";

export interface M5Skill {
	fw: number;
	attribute: string;
	pp: number;
}

export interface M5SkillUnlearned extends M5Skill {
	initial: number;
}

export interface M5SkillLearned extends M5Skill {
	skill: string;
	type: string;
}

export interface M5SkillCalculated extends M5Skill {
	label: string;
	calc: any;
}

export interface M5Attribute {
	value: number;
	bonus: number;
}

export interface M5RollData {
	c: any;
	i: any;
	iType: string;
	rolls: {};
	res: {
		label: string;
	};
}

export interface M5RollTemplate {
	formula: string;
	label: string;
	enabled: boolean;
}

export interface M5RollResult extends M5RollTemplate {
	total: number;
	totalStr: string;
	result: string;
	dice: {};
	css: string;
}

export enum M5EwResult {
	TBD = "",
	FUMBLE = "roll-ew-result-fumble",
	CRITICAL = "roll-ew-result-critical",
	HIGH = "roll-ew-result-high",
	FAIL = "roll-ew-result-fail",
	PASS = "roll-ew-result-pass",
}

export enum M5Attributes {
	ST = "st",
	GW = "gw",
	GS = "gs",
	KO = "ko",
	IN = "in",
	ZT = "zt",
	AU = "au",
	PA = "pa",
	WK = "wk",
}

export enum M5Stats {
	DEFENSE = "defenseBonus",
	ATTACK = "attackBonus",
	DAMAGE = "damageBonus",
	MOVEMENT = "movement",
	RESISTANCE_MIND = "resistanceMind",
	RESISTANCE_BODY = "resistanceBody",
	SPELL_CASTING = "spellCasting",
	BRAWL = "brawl",
	POISON_RESISTANCE = "poisonResistance",
	LP = "lp",
	AP = "ap",
	PROTECTION_LP = "lpProtection",
	PROTECTION_AP = "apProtection",
}

export enum M5ModType {
	ATTRIBUTE = "attribute",
	STAT = "stat",
	SKILL = "skill",
}

export enum M5ModOperation {
	ADD_100 = "add100",
	ADD = "add",
	SET = "set",
	FIXED = "fixed",
	MULTIPLY = "multiply",
	SUBTRACT = "subtract",
	DIVISION = "division",
}

export interface M5ItemMod {
	type: M5ModType;
	id: string;
	operation: M5ModOperation;
	value: number;
}

export interface M5ModPair {
	mod: M5ItemMod;
	source: string;
}

export interface M5ModSource {
	item: string;
	operation: M5ModOperation;
	value: number;
}

export interface M5ModResult {
	mods: Array<M5ModSource>;
	value: number;
}

export interface M5AttributeCalculated extends M5ModResult {
	bonus: number;
}

export interface M5CharacterCalculatedData {
	level: number;
	attributes: {
		st: M5AttributeCalculated;
		gs: M5AttributeCalculated;
		gw: M5AttributeCalculated;
		ko: M5AttributeCalculated;
		in: M5AttributeCalculated;
		zt: M5AttributeCalculated;
		au: M5AttributeCalculated;
		pa: M5AttributeCalculated;
		wk: M5AttributeCalculated;
	};
	stats: {
		lp: M5ModResult;
		ap: M5ModResult;
		lpProtection: M5ModResult;
		apProtection: M5ModResult;
		defense: M5ModResult;
		damageBonus: M5ModResult;
		attackBonus: M5ModResult;
		defenseBonus: M5ModResult;
		movement: M5ModResult;
		resistanceMind: M5ModResult;
		resistanceBody: M5ModResult;
		spellCasting: M5ModResult;
		brawl: M5ModResult;
		brawlEw: number;
		poisonResistance: M5ModResult;
		enduranceBonus: number;
	};
	skillMods: {};
	skills: {
		innate: {};
		general: {};
		combat: {};
		language: {};
		custom: {};
	};
	gear: {
		weapons: {};
		defensiveWeapons: {};
		armor: {};
		items: {};
		effects: {};
	};
	spells: {};
	kampfkuenste: {};
}

export function enumKeys<O extends object, K extends keyof O = keyof O>(obj: O): K[] {
	return Object.keys(obj).filter((k) => Number.isNaN(+k)) as K[];
}
