"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.EfficientEngineer = void 0;
const reference_data_1 = require("@firestone-hs/reference-data");
const utils_1 = require("../../../services/utils");
const card_interface_1 = require("../../card.interface");
const _card_mappings_1 = require("../_card-mappings");
const timewarped_murk_eye_1 = require("./timewarped-murk-eye");
const young_murk_eye_1 = require("./young-murk-eye");
exports.EfficientEngineer = {
    cardIds: ["BG31_301", "BG31_301_G"],
    battlecry: (minion, input) => {
        var _a, _b;
        const mult = minion.cardId === "BG31_301_G" ? 2 : 1;
        const allCards = input.gameState.allCards;
        for (let i = 0; i < mult; i++) {
            const candidates = input.board
                .filter((e) => ![...young_murk_eye_1.YoungMurkEye.cardIds, ...timewarped_murk_eye_1.TimewarpedMurkEye.cardIds].includes(e.cardId))
                .filter((m) => hasEndOfTurnMechanics(m.cardId, allCards) ||
                m.enchantments.some((e) => hasEndOfTurnMechanics(e.cardId, allCards)));
            const target = (0, utils_1.pickRandom)(candidates);
            if (target) {
                const endOfTurnCandidates = [target.cardId, ...target.enchantments.map((e) => e.cardId)].filter((e) => hasEndOfTurnMechanics(e, allCards));
                for (const cardId of endOfTurnCandidates) {
                    const endOfTurnImpl = _card_mappings_1.cardMappings[cardId];
                    if ((0, card_interface_1.hasEndOfTurn)(endOfTurnImpl)) {
                        const baseLoops = 1 +
                            ((_b = (_a = input.hero.trinkets) === null || _a === void 0 ? void 0 : _a.filter((t) => t.cardId === "BG32_MagicItem_367").length) !== null && _b !== void 0 ? _b : 0);
                        const minionLoops = input.board.some((e) => e.cardId === "BG26_ICC_901_G")
                            ? 3
                            : input.board.some((e) => e.cardId === "BG26_ICC_901")
                                ? 2
                                : 1;
                        const numberOfLoops = baseLoops * minionLoops;
                        for (let i = 0; i < numberOfLoops; i++) {
                            endOfTurnImpl.endOfTurn(target, input);
                        }
                    }
                }
            }
        }
        return true;
    },
};
const hasEndOfTurnMechanics = (cardId, allCards) => {
    var _a;
    const byImpl = _card_mappings_1.cardMappings[cardId];
    if ((0, card_interface_1.hasEndOfTurn)(byImpl)) {
        return true;
    }
    return (_a = allCards.getCard(cardId).mechanics) === null || _a === void 0 ? void 0 : _a.includes(reference_data_1.GameTag[reference_data_1.GameTag.END_OF_TURN]);
};
//# sourceMappingURL=efficient-engineer.js.map