"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ChefsChoice = exports.addChefsChoiceToHand = void 0;
const reference_data_1 = require("@firestone-hs/reference-data");
const cards_in_hand_1 = require("../../../simulation/cards-in-hand");
const utils_1 = require("../../../services/utils");
const addChefsChoiceToHand = (target, hero, board, gameState) => {
    var _a, _b, _c, _d;
    const ref = gameState.allCards.getCard(target.cardId);
    if (((_a = ref.type) === null || _a === void 0 ? void 0 : _a.toUpperCase()) !== reference_data_1.CardType[reference_data_1.CardType.MINION]) {
        return;
    }
    const tier = (_b = hero.tavernTier) !== null && _b !== void 0 ? _b : 6;
    const excluded = [target.cardId];
    const races = (_c = ref.races) !== null && _c !== void 0 ? _c : [];
    let cardId;
    if (races.length) {
        const tribe = reference_data_1.Race[races[0]];
        cardId = gameState.cardsData.getRandomMinionForTribe(tribe, tier, excluded);
    }
    else {
        for (let i = 0; i < 40; i++) {
            const id = gameState.cardsData.getRandomMinionForTavernTier(Math.min(tier, 6));
            if (!id || excluded.includes(id)) {
                continue;
            }
            const c = gameState.allCards.getCard(id);
            if (!((_d = c.races) === null || _d === void 0 ? void 0 : _d.length)) {
                cardId = id;
                break;
            }
        }
    }
    if (cardId) {
        (0, cards_in_hand_1.addCardsInHand)(hero, board, [cardId], gameState);
    }
};
exports.addChefsChoiceToHand = addChefsChoiceToHand;
exports.ChefsChoice = {
    cardIds: ["BG28_518"],
    castTavernSpell: (_spellCardId, input) => {
        var _a;
        const target = (_a = input.target) !== null && _a !== void 0 ? _a : (0, utils_1.pickRandom)(input.board.filter((e) => e.health > 0 && !e.definitelyDead));
        if (target) {
            (0, exports.addChefsChoiceToHand)(target, input.hero, input.board, input.gameState);
        }
    },
};
//# sourceMappingURL=chefs-choice.js.map