"use strict";
// Copyright 2023 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
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.UnlockDiscriminator = exports.EmptyUnlock = exports.MultiUnlock = exports.NftUnlock = exports.AnchorUnlock = exports.AccountUnlock = exports.ReferenceUnlock = exports.SignatureUnlock = exports.Unlock = exports.UnlockType = void 0;
const class_transformer_1 = require("class-transformer");
const signature_1 = require("../../signature");
/**
 * All of the unlock types.
 */
var UnlockType;
(function (UnlockType) {
    /**
     * A signature unlock.
     */
    UnlockType[UnlockType["Signature"] = 0] = "Signature";
    /**
     * A reference unlock.
     */
    UnlockType[UnlockType["Reference"] = 1] = "Reference";
    /**
     *  An account unlock.
     */
    UnlockType[UnlockType["Account"] = 2] = "Account";
    /**
     *  An Anchor unlock.
     */
    UnlockType[UnlockType["Anchor"] = 3] = "Anchor";
    /**
     *  An NFT unlock.
     */
    UnlockType[UnlockType["Nft"] = 4] = "Nft";
    /**
     *  A multi unlock.
     */
    UnlockType[UnlockType["Multi"] = 5] = "Multi";
    /**
     *  An empty unlock.
     */
    UnlockType[UnlockType["Empty"] = 6] = "Empty";
})(UnlockType || (UnlockType = {}));
exports.UnlockType = UnlockType;
/**
 * The base class for unlocks.
 */
class Unlock {
    /**
     * @param type The type of unlock.
     */
    constructor(type) {
        this.type = type;
    }
}
exports.Unlock = Unlock;
/**
 * An unlock holding one or more signatures unlocking one or more inputs..
 */
class SignatureUnlock extends Unlock {
    /**
     * @param signature An Ed25519 signature.
     */
    constructor(signature) {
        super(UnlockType.Signature);
        this.signature = signature;
    }
}
__decorate([
    (0, class_transformer_1.Type)(() => signature_1.Ed25519Signature)
], SignatureUnlock.prototype, "signature", void 0);
exports.SignatureUnlock = SignatureUnlock;
/**
 * An unlock which must reference a previous unlock which unlocks
 * also the input at the same index as this Reference Unlock.
 */
class ReferenceUnlock extends Unlock {
    /**
     * @param reference An index referencing a previous unlock.
     */
    constructor(reference) {
        super(UnlockType.Reference);
        this.reference = reference;
    }
}
exports.ReferenceUnlock = ReferenceUnlock;
/**
 * An unlock which must reference a previous unlock which unlocks the account that the input is locked to.
 */
class AccountUnlock extends Unlock {
    /**
     * @param reference An index referencing a previous unlock.
     */
    constructor(reference) {
        super(UnlockType.Account);
        this.reference = reference;
    }
}
exports.AccountUnlock = AccountUnlock;
/**
 * An unlock which must reference a previous unlock which unlocks the anchor that the input is locked to.
 */
class AnchorUnlock extends Unlock {
    /**
     * @param reference An index referencing a previous unlock.
     */
    constructor(reference) {
        super(UnlockType.Anchor);
        this.reference = reference;
    }
}
exports.AnchorUnlock = AnchorUnlock;
/**
 * An unlock which must reference a previous unlock which unlocks the NFT that the input is locked to.
 */
class NftUnlock extends Unlock {
    /**
     * @param reference An index referencing a previous unlock.
     */
    constructor(reference) {
        super(UnlockType.Nft);
        this.reference = reference;
    }
}
exports.NftUnlock = NftUnlock;
/**
 * Used to maintain correct index relationship between addresses and signatures when unlocking a MultiUnlock where not all addresses are unlocked.
 */
class EmptyUnlock extends Unlock {
    constructor() {
        super(UnlockType.Empty);
    }
}
exports.EmptyUnlock = EmptyUnlock;
/**
 * Unlocks a MultiAddress with a list of other unlocks.
 */
class MultiUnlock extends Unlock {
    /**
     * @param unlocks The inner unlocks.
     */
    constructor(unlocks) {
        super(UnlockType.Multi);
        this.unlocks = unlocks;
    }
}
__decorate([
    (0, class_transformer_1.Type)(() => Unlock, {
        discriminator: {
            property: 'type',
            subTypes: [
                {
                    value: SignatureUnlock,
                    name: UnlockType.Signature,
                },
                {
                    value: ReferenceUnlock,
                    name: UnlockType.Reference,
                },
                {
                    value: AccountUnlock,
                    name: UnlockType.Account,
                },
                {
                    value: AnchorUnlock,
                    name: UnlockType.Anchor,
                },
                {
                    value: NftUnlock,
                    name: UnlockType.Nft,
                },
                {
                    value: EmptyUnlock,
                    name: UnlockType.Empty,
                },
            ],
        },
    })
], MultiUnlock.prototype, "unlocks", void 0);
exports.MultiUnlock = MultiUnlock;
const UnlockDiscriminator = {
    property: 'type',
    subTypes: [
        {
            value: SignatureUnlock,
            name: UnlockType.Signature,
        },
        {
            value: ReferenceUnlock,
            name: UnlockType.Reference,
        },
        {
            value: AccountUnlock,
            name: UnlockType.Account,
        },
        {
            value: AnchorUnlock,
            name: UnlockType.Anchor,
        },
        {
            value: NftUnlock,
            name: UnlockType.Nft,
        },
        {
            value: MultiUnlock,
            name: UnlockType.Multi,
        },
        {
            value: EmptyUnlock,
            name: UnlockType.Empty,
        },
    ],
};
exports.UnlockDiscriminator = UnlockDiscriminator;
//# sourceMappingURL=unlock.js.map