"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.NoSirenSteal = void 0;
const isaac_typescript_definitions_1 = require("isaac-typescript-definitions");
const decorators_1 = require("../../../decorators");
const Feature_1 = require("../../private/Feature");
const v = {
    run: {
        familiarBlacklist: [],
    },
};
class NoSirenSteal extends Feature_1.Feature {
    /** @internal */
    v = v;
    /** @internal */
    constructor() {
        super();
        this.callbacksUsed = [
            // 27
            [
                isaac_typescript_definitions_1.ModCallback.POST_NPC_INIT,
                this.postNPCInitSirenHelper,
                [isaac_typescript_definitions_1.EntityType.SIREN_HELPER],
            ],
        ];
    }
    // ModCallback.POST_NPC_INIT (27)
    // EntityType.SIREN_HELPER (966)
    postNPCInitSirenHelper = (npc) => {
        this.checkReturnFamiliarToPlayer(npc);
    };
    checkReturnFamiliarToPlayer(npc) {
        if (npc.Target === undefined) {
            return;
        }
        const familiar = npc.Target.ToFamiliar();
        if (familiar === undefined) {
            return;
        }
        if (this.blacklistEntryExists(familiar.Variant, familiar.SubType)) {
            npc.Remove();
            familiar.AddToFollowers();
        }
    }
    blacklistEntryExists(incomingFamiliarVariant, incomingFamiliarSubType) {
        for (const familiarTuple of v.run.familiarBlacklist) {
            const [familiarVariant, familiarSubType] = familiarTuple;
            if (familiarVariant === incomingFamiliarVariant &&
                familiarSubType === incomingFamiliarSubType) {
                // There is an entry that matches the variant and sub-type exactly.
                return true;
            }
            if (familiarVariant === incomingFamiliarVariant &&
                familiarSubType === undefined) {
                // There is an entry that matches all sub-types for this variant.
                return true;
            }
        }
        return false;
    }
    /**
     * Blacklists a familiar from being stolen by The Siren boss. This should be called once at the
     * beginning of every run.
     *
     * In order to use this function, you must upgrade your mod with `ISCFeature.NO_SIREN_STEAL`.
     *
     * @param familiarVariant The familiar variant to blacklist.
     * @param familiarSubType The sub-type to blacklist. Optional. The default is to blacklist all
     *                        sub-types of the given variant.
     * @public
     */
    setFamiliarNoSirenSteal(familiarVariant, familiarSubType) {
        if (this.blacklistEntryExists(familiarVariant, familiarSubType)) {
            return;
        }
        v.run.familiarBlacklist.push([familiarVariant, familiarSubType]);
    }
}
exports.NoSirenSteal = NoSirenSteal;
__decorate([
    decorators_1.Exported
], NoSirenSteal.prototype, "setFamiliarNoSirenSteal", null);
