"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEffectiveTribesEnumBase = exports.hasSpellSchool = exports.hasMechanic = exports.hasCorrectTribe = exports.getEffectiveTechLevel = exports.isBattlegroundsCard = exports.normalizeDeckHeroDbfId = exports.isArena = exports.getDefaultHeroDbfIdForClass = exports.formatGameTypeReverse = exports.formatGameType = exports.formatFormatReverse = exports.formatFormat = exports.ALL_CLASSES = void 0;
const public_api_1 = require("../public-api");
exports.ALL_CLASSES = [
    'deathknight',
    'demonhunter',
    'druid',
    'hunter',
    'mage',
    'paladin',
    'priest',
    'rogue',
    'shaman',
    'warlock',
    'warrior',
];
const formatFormat = (format) => {
    switch (format) {
        case public_api_1.GameFormat.FT_STANDARD:
            return 'standard';
        case public_api_1.GameFormat.FT_CLASSIC:
            return 'classic';
        case public_api_1.GameFormat.FT_TWIST:
            return 'twist';
        case public_api_1.GameFormat.FT_WILD:
        default:
            return 'wild';
    }
};
exports.formatFormat = formatFormat;
const formatFormatReverse = (format) => {
    switch (format) {
        case 'standard':
            return public_api_1.GameFormat.FT_STANDARD;
        case 'classic':
            return public_api_1.GameFormat.FT_CLASSIC;
        case 'twist':
            return public_api_1.GameFormat.FT_TWIST;
        case 'wild':
        default:
            return public_api_1.GameFormat.FT_WILD;
    }
};
exports.formatFormatReverse = formatFormatReverse;
const formatGameType = (gameType) => {
    switch (gameType) {
        case public_api_1.GameType.GT_UNKNOWN:
            return 'unknown';
        case public_api_1.GameType.GT_VS_AI:
            return 'practice';
        case public_api_1.GameType.GT_VS_FRIEND:
            return 'friendly';
        case public_api_1.GameType.GT_TUTORIAL:
            return 'tutorial';
        case public_api_1.GameType.GT_ARENA:
            return 'arena';
        case public_api_1.GameType.GT_UNDERGROUND_ARENA:
            return 'arena-underground';
        case public_api_1.GameType.GT_RANKED:
            return 'ranked';
        case public_api_1.GameType.GT_CASUAL:
            return 'casual';
        case public_api_1.GameType.GT_TAVERNBRAWL:
        case public_api_1.GameType.GT_TB_1P_VS_AI:
        case public_api_1.GameType.GT_TB_2P_COOP:
        case public_api_1.GameType.GT_FSG_BRAWL_VS_FRIEND:
        case public_api_1.GameType.GT_FSG_BRAWL:
        case public_api_1.GameType.GT_FSG_BRAWL_1P_VS_AI:
        case public_api_1.GameType.GT_FSG_BRAWL_2P_COOP:
            return 'tavern-brawl';
        case public_api_1.GameType.GT_BATTLEGROUNDS:
        case public_api_1.GameType.GT_BATTLEGROUNDS_FRIENDLY:
        case public_api_1.GameType.GT_BATTLEGROUNDS_AI_VS_AI:
        case public_api_1.GameType.GT_BATTLEGROUNDS_PLAYER_VS_AI:
            return 'battlegrounds';
        case public_api_1.GameType.GT_BATTLEGROUNDS_DUO:
        case public_api_1.GameType.GT_BATTLEGROUNDS_DUO_VS_AI:
        case public_api_1.GameType.GT_BATTLEGROUNDS_DUO_FRIENDLY:
        case public_api_1.GameType.GT_BATTLEGROUNDS_DUO_AI_VS_AI:
            return 'battlegrounds-duo';
        case public_api_1.GameType.GT_MERCENARIES_AI_VS_AI:
            return 'mercenaries-ai-vs-ai';
        case public_api_1.GameType.GT_MERCENARIES_FRIENDLY:
            return 'mercenaries-friendly';
        case public_api_1.GameType.GT_MERCENARIES_PVE:
            return 'mercenaries-pve';
        case public_api_1.GameType.GT_MERCENARIES_PVP:
            return 'mercenaries-pvp';
        case public_api_1.GameType.GT_MERCENARIES_PVE_COOP:
            return 'mercenaries-pve-coop';
        case public_api_1.GameType.GT_PVPDR:
            return 'duels';
        case public_api_1.GameType.GT_PVPDR_PAID:
            return 'paid-duels';
        default:
            console.warn('unsupported game type', gameType);
            return 'unknown';
    }
};
exports.formatGameType = formatGameType;
const formatGameTypeReverse = (gameType) => {
    switch (gameType) {
        case 'unknown':
            return public_api_1.GameType.GT_UNKNOWN;
        case 'practice':
            return public_api_1.GameType.GT_VS_AI;
        case 'friendly':
            return public_api_1.GameType.GT_VS_FRIEND;
        case 'tutorial':
            return public_api_1.GameType.GT_TUTORIAL;
        case 'arena':
            return public_api_1.GameType.GT_ARENA;
        case 'arena-underground':
            return public_api_1.GameType.GT_UNDERGROUND_ARENA;
        case 'ranked':
            return public_api_1.GameType.GT_RANKED;
        case 'casual':
            return public_api_1.GameType.GT_CASUAL;
        case 'tavern-brawl':
            return public_api_1.GameType.GT_TAVERNBRAWL;
        case 'battlegrounds':
            return public_api_1.GameType.GT_BATTLEGROUNDS;
        case 'battlegrounds-duo':
            return public_api_1.GameType.GT_BATTLEGROUNDS_DUO;
        case 'mercenaries-ai-vs-ai':
            return public_api_1.GameType.GT_MERCENARIES_AI_VS_AI;
        case 'mercenaries-friendly':
            return public_api_1.GameType.GT_MERCENARIES_FRIENDLY;
        case 'mercenaries-pve':
            return public_api_1.GameType.GT_MERCENARIES_PVE;
        case 'mercenaries-pvp':
            return public_api_1.GameType.GT_MERCENARIES_PVP;
        case 'mercenaries-pve-coop':
            return public_api_1.GameType.GT_MERCENARIES_PVE_COOP;
        case 'duels':
            return public_api_1.GameType.GT_PVPDR;
        case 'paid-duels':
            return public_api_1.GameType.GT_PVPDR_PAID;
        default:
            console.warn('unsupported game type', gameType);
            return public_api_1.GameType.GT_UNKNOWN;
    }
};
exports.formatGameTypeReverse = formatGameTypeReverse;
const getDefaultHeroDbfIdForClass = (playerClass) => {
    switch (playerClass === null || playerClass === void 0 ? void 0 : playerClass.toLowerCase()) {
        case 'deathknight':
            return 78065;
        case 'demonhunter':
            return 56550;
        case 'druid':
            return 274;
        case 'hunter':
            return 31;
        case 'mage':
            return 637;
        case 'paladin':
            return 671;
        case 'priest':
            return 813;
        case 'rogue':
            return 930;
        case 'shaman':
            return 1066;
        case 'warlock':
            return 893;
        case 'warrior':
            return 7;
        default:
            console.warn('Could not normalize hero card id', playerClass);
            return 7;
    }
};
exports.getDefaultHeroDbfIdForClass = getDefaultHeroDbfIdForClass;
const isArena = (gameType) => {
    return ([public_api_1.GameType.GT_ARENA, public_api_1.GameType.GT_UNDERGROUND_ARENA].includes(gameType) ||
        gameType === 'arena' ||
        gameType === 'arena-underground');
};
exports.isArena = isArena;
const normalizeDeckHeroDbfId = (heroDbfId, cards, duelsClass, deckClass) => {
    var _a, _b;
    const cardFromHeroDbfId = cards.getCardFromDbfId(heroDbfId);
    switch (cardFromHeroDbfId.id) {
        case public_api_1.CardIds.VanndarStormpikeTavernBrawl:
            switch (duelsClass !== null && duelsClass !== void 0 ? duelsClass : deckClass) {
                case public_api_1.CardClass.DEMONHUNTER:
                    return cards.getCard(public_api_1.CardIds.VanndarStormpike_VanndarStormpikeTavernBrawl_PVPDR_Hero_Vanndarv1)
                        .dbfId;
                case public_api_1.CardClass.HUNTER:
                    return cards.getCard(public_api_1.CardIds.VanndarStormpike_VanndarStormpikeTavernBrawl_PVPDR_Hero_Vanndarv2)
                        .dbfId;
                case public_api_1.CardClass.PALADIN:
                    return cards.getCard(public_api_1.CardIds.VanndarStormpike_VanndarStormpikeTavernBrawl_PVPDR_Hero_Vanndarv3)
                        .dbfId;
                case public_api_1.CardClass.PRIEST:
                    return cards.getCard(public_api_1.CardIds.VanndarStormpike_VanndarStormpikeTavernBrawl_PVPDR_Hero_Vanndarv4)
                        .dbfId;
                case public_api_1.CardClass.ROGUE:
                    return cards.getCard(public_api_1.CardIds.VanndarStormpike_VanndarStormpikeTavernBrawl_PVPDR_Hero_Vanndarv5)
                        .dbfId;
            }
            break;
        case public_api_1.CardIds.DrektharTavernBrawl:
            switch (duelsClass !== null && duelsClass !== void 0 ? duelsClass : deckClass) {
                case public_api_1.CardClass.DRUID:
                    return cards.getCard(public_api_1.CardIds.Drekthar_DrektharTavernBrawl_PVPDR_Hero_DrekTharv1).dbfId;
                case public_api_1.CardClass.MAGE:
                    return cards.getCard(public_api_1.CardIds.Drekthar_DrektharTavernBrawl_PVPDR_Hero_DrekTharv2).dbfId;
                case public_api_1.CardClass.SHAMAN:
                    return cards.getCard(public_api_1.CardIds.Drekthar_DrektharTavernBrawl_PVPDR_Hero_DrekTharv3).dbfId;
                case public_api_1.CardClass.WARLOCK:
                    return cards.getCard(public_api_1.CardIds.Drekthar_DrektharTavernBrawl_PVPDR_Hero_DrekTharv4).dbfId;
                case public_api_1.CardClass.WARRIOR:
                    return cards.getCard(public_api_1.CardIds.Drekthar_DrektharTavernBrawl_PVPDR_Hero_DrekTharv5).dbfId;
            }
            break;
    }
    if (duelsClass || public_api_1.allDuelsHeroesExtended.includes(cardFromHeroDbfId.id)) {
        return heroDbfId;
    }
    const playerClass = public_api_1.CardClass[(_b = (_a = cards.getCard(heroDbfId)) === null || _a === void 0 ? void 0 : _a.playerClass) === null || _b === void 0 ? void 0 : _b.toUpperCase()];
    if (!playerClass) {
        return heroDbfId;
    }
    switch (playerClass) {
        case public_api_1.CardClass.DEATHKNIGHT:
            return 78065;
        case public_api_1.CardClass.DEMONHUNTER:
            return 56550;
        case public_api_1.CardClass.DRUID:
            return 274;
        case public_api_1.CardClass.HUNTER:
            return 31;
        case public_api_1.CardClass.MAGE:
            return 637;
        case public_api_1.CardClass.PALADIN:
            return 671;
        case public_api_1.CardClass.PRIEST:
            return 813;
        case public_api_1.CardClass.ROGUE:
            return 930;
        case public_api_1.CardClass.SHAMAN:
            return 1066;
        case public_api_1.CardClass.WARLOCK:
            return 893;
        case public_api_1.CardClass.WARRIOR:
            return 7;
        default:
            return heroDbfId;
    }
};
exports.normalizeDeckHeroDbfId = normalizeDeckHeroDbfId;
const isBattlegroundsCard = (card) => {
    return !!card.techLevel || !!card.battlegroundsNormalDbfId || !!card.battlegroundsPremiumDbfId;
};
exports.isBattlegroundsCard = isBattlegroundsCard;
const getEffectiveTechLevel = (card, allCards) => {
    var _a, _b;
    if (card.techLevel) {
        return card.techLevel;
    }
    if (card.battlegroundsNormalDbfId) {
        const normalCard = allCards.getCardFromDbfId(card.battlegroundsNormalDbfId);
        return (_a = normalCard.techLevel) !== null && _a !== void 0 ? _a : 1;
    }
    if (card.battlegroundsPremiumDbfId) {
        const premiumCard = allCards.getCardFromDbfId(card.battlegroundsPremiumDbfId);
        return (_b = premiumCard.techLevel) !== null && _b !== void 0 ? _b : 1;
    }
    return 1;
};
exports.getEffectiveTechLevel = getEffectiveTechLevel;
const hasCorrectTribe = (card, targetTribe) => {
    const cardTribes = exports.getEffectiveTribesEnumBase(card);
    return (cardTribes.includes(targetTribe) ||
        cardTribes.includes(public_api_1.Race.ALL) ||
        (targetTribe === public_api_1.Race.ALL && cardTribes.filter((t) => t !== public_api_1.Race.BLANK).length > 0));
};
exports.hasCorrectTribe = hasCorrectTribe;
const hasMechanic = (card, mechanic) => {
    var _a;
    return (_a = card.mechanics) === null || _a === void 0 ? void 0 : _a.includes(public_api_1.GameTag[mechanic]);
};
exports.hasMechanic = hasMechanic;
const hasSpellSchool = (card, spellSchool) => {
    var _a;
    return ((_a = card.spellSchool) === null || _a === void 0 ? void 0 : _a.toUpperCase()) === public_api_1.SpellSchool[spellSchool];
};
exports.hasSpellSchool = hasSpellSchool;
const getEffectiveTribesEnumBase = (card) => {
    var _a;
    return !!((_a = card.races) === null || _a === void 0 ? void 0 : _a.length) ? card.races.map((r) => public_api_1.Race[r]) : [public_api_1.Race.BLANK];
};
exports.getEffectiveTribesEnumBase = getEffectiveTribesEnumBase;
//# sourceMappingURL=hs-utils.js.map