"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isMinionGolden = exports.makeMinionGolden = void 0;
const reference_data_1 = require("@firestone-hs/reference-data");
const eternal_portrait_1 = require("../../cards/impl/trinket/eternal-portrait");
const utils_1 = require("../../utils");
const add_minion_to_board_1 = require("../add-minion-to-board");
const remove_minion_from_board_1 = require("../remove-minion-from-board");
const stats_1 = require("../stats");
const makeMinionGolden = (target, source, targetBoard, targetBoardHero, otherBoard, otherHero, gameState) => {
    var _a, _b;
    if ((0, exports.isMinionGolden)(target, gameState.allCards)) {
        return;
    }
    gameState.spectator.registerPowerTarget(source, target, targetBoard, null, null);
    (0, remove_minion_from_board_1.handleMinionRemovedAuraEffect)(targetBoard, target, targetBoardHero, gameState);
    removeMinionAuraEffectsForGolden(target, targetBoardHero);
    const refCard = gameState.allCards.getCard(target.cardId);
    let goldenCard = gameState.allCards.getCardFromDbfId(refCard.battlegroundsPremiumDbfId);
    if (!(goldenCard === null || goldenCard === void 0 ? void 0 : goldenCard.id)) {
        goldenCard = refCard;
    }
    target.cardId = goldenCard.id;
    target.entityId = gameState.sharedState.currentEntityId++;
    (0, stats_1.modifyStats)(target, null, refCard.attack, refCard.health, targetBoard, targetBoardHero, gameState, true, false);
    (0, add_minion_to_board_1.handleAddedMinionAuraEffect)(targetBoard, targetBoardHero, otherBoard, otherHero, target, gameState, true, false);
    const hasDivineShield = target.divineShield;
    const hasReborn = target.reborn;
    const avengeCurrent = target.avengeCurrent;
    (0, utils_1.addImpliedMechanics)(target, gameState.cardsData);
    target.divineShield = hasDivineShield;
    target.reborn =
        hasReborn ||
            (((_a = goldenCard.mechanics) === null || _a === void 0 ? void 0 : _a.includes(reference_data_1.GameTag[reference_data_1.GameTag.REBORN])) &&
                !((_b = refCard.mechanics) === null || _b === void 0 ? void 0 : _b.includes(reference_data_1.GameTag[reference_data_1.GameTag.REBORN])));
    target.avengeCurrent = avengeCurrent;
    target.gildedInCombat = true;
};
exports.makeMinionGolden = makeMinionGolden;
const isMinionGolden = (entity, allCards) => {
    const ref = allCards.getCard(entity.cardId);
    return ref.premium;
};
exports.isMinionGolden = isMinionGolden;
const removeMinionAuraEffectsForGolden = (entity, hero) => {
    switch (entity.cardId) {
        case "BG25_008":
        case "BG25_008_G":
            const eternalKnightBuffToRemove = hero.globalInfo.EternalKnightsDeadThisGame;
            const eternalKnighMultiplier = entity.cardId === "BG25_008_G" ? 2 : 1;
            entity.health = Math.max(1, entity.health - eternal_portrait_1.eternalKnightHealth * eternalKnighMultiplier * eternalKnightBuffToRemove);
            entity.attack = Math.max(0, entity.attack - eternal_portrait_1.eternalKnightAttack * eternalKnighMultiplier * eternalKnightBuffToRemove);
            break;
        case "BGDUO31_208":
        case "BGDUO31_208_G":
            const sanlaynBuffToRemove = hero.globalInfo.SanlaynScribesDeadThisGame;
            const sanlaynMultiplier = entity.cardId === "BGDUO31_208_G" ? 2 : 1;
            entity.health = Math.max(1, entity.health - sanlaynMultiplier * sanlaynBuffToRemove);
            entity.attack = Math.max(0, entity.attack - sanlaynMultiplier * sanlaynBuffToRemove);
            break;
        case "BG_TTN_401":
        case "BG_TTN_401_G":
            const multiplierAstral = entity.cardId === "BG_TTN_401_G" ? 2 : 1;
            const statsBonusAstralToRemove = hero.globalInfo.AstralAutomatonsSummonedThisGame - 1;
            entity.health = Math.max(1, entity.health - 3 * multiplierAstral * statsBonusAstralToRemove);
            entity.attack = Math.max(0, entity.attack - 2 * multiplierAstral * statsBonusAstralToRemove);
            break;
        case "BG31_176":
        case "BG31_176_G":
            const multiplierDrBoom = entity.cardId === "BG31_176_G" ? 2 : 1;
            entity.health = Math.max(1, entity.health - 2 * hero.globalInfo.MagnetizedThisGame * multiplierDrBoom);
            entity.attack = Math.max(0, entity.attack - 2 * hero.globalInfo.MagnetizedThisGame * multiplierDrBoom);
            break;
    }
};
//# sourceMappingURL=golden.js.map