import { round } from 'lodash';
import { RuleDataAccessors } from '../RuleData';
import { AdjustmentTypeEnum } from '../Value';
import { AbilityStatEnum, CURRENCY_VALUE, FEET_IN_MILES } from './constants';
export function convertFeetToMiles(number, precision = 2) {
    return round(number / FEET_IN_MILES, precision);
}
/**
 *
 * @param key
 * @param displayConfiguration
 */
export function getDisplayConfigurationValue(key, displayConfiguration) {
    return displayConfiguration[key];
}
/**
 *
 * @param coin
 * @param ruleData
 */
export function convertTotalCoinToGold(coin, ruleData) {
    let totalGp = RuleDataAccessors.getCurrencyData(ruleData).reduce((acc, currency) => {
        if (currency.name) {
            let key = currency.name.toLowerCase();
            if (coin.hasOwnProperty(key)) {
                acc += coin[key] * currency.conversionFromGp;
            }
        }
        return acc;
    }, 0);
    return Math.floor(totalGp);
}
/**
 *
 * @param multiplier
 * @param adjustments
 */
export function getCurrencyTransactionAdjustment(multiplier, adjustments) {
    let adjustedCurrency = {};
    Object.keys(adjustments).forEach((coinKey) => {
        adjustedCurrency[coinKey] = Math.min(adjustments[coinKey] * multiplier, CURRENCY_VALUE.MAX);
    });
    return adjustedCurrency;
}
// returns the adjusment type that corresponds to a given stat id
// Only returns types that are defined in the STAT_REPLACEMENT_TYPE_LOOKUP
export function getAdjustmentTypeByStatId(statId) {
    switch (statId) {
        case AbilityStatEnum.STRENGTH:
            return AdjustmentTypeEnum.USE_STRENGTH;
        case AbilityStatEnum.DEXTERITY:
            return AdjustmentTypeEnum.USE_DEXTERITY;
        case AbilityStatEnum.CONSTITUTION:
            return AdjustmentTypeEnum.USE_CONSTITUTION;
        case AbilityStatEnum.INTELLIGENCE:
            return AdjustmentTypeEnum.USE_INTELLIGENCE;
        case AbilityStatEnum.WISDOM:
            return AdjustmentTypeEnum.USE_WISDOM;
        case AbilityStatEnum.CHARISMA:
            return AdjustmentTypeEnum.USE_CHARISMA;
        default:
            return null;
    }
}
