// 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;
};
import { Type } from 'class-transformer';
import { ContextInputDiscriminator } from '../../context_input';
import { Input, InputDiscriminator } from '../../input';
import { Output, OutputDiscriminator } from '../../output';
import { Payload, PayloadType } from '../payload';
import { TaggedDataPayload } from '../tagged/tagged';
/**
 * PayloadDiscriminator for payloads inside of a Transaction.
 */
var PayloadDiscriminator = {
    property: 'type',
    subTypes: [
        { value: TaggedDataPayload, name: PayloadType.TaggedData },
    ]
};
/**
 * A transaction.
 */
var Transaction = /** @class */ (function () {
    /**
     * @param networkId The ID of the network the transaction was issued to.
     * @param inputs The inputs of the transaction.
     * @param outputs The outputs of the transaction.
     * @param payload An optional Tagged Data payload.
     *
     */
    function Transaction(networkId, creationSlot, contextInputs, inputs, allotments, outputs, payload) {
        this.networkId = networkId;
        this.creationSlot = creationSlot;
        this.contextInputs = contextInputs;
        this.inputs = inputs;
        this.allotments = allotments;
        this.payload = payload;
        this.outputs = outputs;
    }
    Transaction.prototype.setCapabilities = function (capabilities) {
        if (capabilities.some(function (c) { return c != 0; })) {
            this.capabilities =
                '0x' +
                    Buffer.from(capabilities.buffer, capabilities.byteOffset, capabilities.byteLength).toString('hex');
        }
        else {
            this.capabilities = undefined;
        }
    };
    Transaction.prototype.withCapabilities = function (capabilities) {
        this.setCapabilities(capabilities);
        return this;
    };
    /** Get the capability bitflags of the transaction. */
    Transaction.prototype.getCapabilities = function () {
        return this.capabilities !== undefined
            ? Uint8Array.from(Buffer.from(this.capabilities.substring(2), 'hex'))
            : new Uint8Array();
    };
    __decorate([
        Type(function () { return Input; }, {
            discriminator: ContextInputDiscriminator
        })
    ], Transaction.prototype, "contextInputs");
    __decorate([
        Type(function () { return Input; }, {
            discriminator: InputDiscriminator
        })
    ], Transaction.prototype, "inputs");
    __decorate([
        Type(function () { return Payload; }, {
            discriminator: PayloadDiscriminator
        })
    ], Transaction.prototype, "payload");
    __decorate([
        Type(function () { return Output; }, {
            discriminator: OutputDiscriminator
        })
    ], Transaction.prototype, "outputs");
    return Transaction;
}());
export { Transaction };
//# sourceMappingURL=transaction.js.map