"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.Transaction = void 0;
const class_transformer_1 = require("class-transformer");
const context_input_1 = require("../../context_input");
const input_1 = require("../../input");
const output_1 = require("../../output");
const payload_1 = require("../payload");
const tagged_1 = require("../tagged/tagged");
/**
 * PayloadDiscriminator for payloads inside of a Transaction.
 */
const PayloadDiscriminator = {
    property: 'type',
    subTypes: [
        { value: tagged_1.TaggedDataPayload, name: payload_1.PayloadType.TaggedData },
    ],
};
/**
 * A transaction.
 */
class Transaction {
    /**
     * @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.
     *
     */
    constructor(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;
    }
    setCapabilities(capabilities) {
        if (capabilities.some((c) => c != 0)) {
            this.capabilities =
                '0x' +
                    Buffer.from(capabilities.buffer, capabilities.byteOffset, capabilities.byteLength).toString('hex');
        }
        else {
            this.capabilities = undefined;
        }
    }
    withCapabilities(capabilities) {
        this.setCapabilities(capabilities);
        return this;
    }
    /** Get the capability bitflags of the transaction. */
    getCapabilities() {
        return this.capabilities !== undefined
            ? Uint8Array.from(Buffer.from(this.capabilities.substring(2), 'hex'))
            : new Uint8Array();
    }
}
__decorate([
    (0, class_transformer_1.Type)(() => input_1.Input, {
        discriminator: context_input_1.ContextInputDiscriminator,
    })
], Transaction.prototype, "contextInputs", void 0);
__decorate([
    (0, class_transformer_1.Type)(() => input_1.Input, {
        discriminator: input_1.InputDiscriminator,
    })
], Transaction.prototype, "inputs", void 0);
__decorate([
    (0, class_transformer_1.Type)(() => payload_1.Payload, {
        discriminator: PayloadDiscriminator,
    })
], Transaction.prototype, "payload", void 0);
__decorate([
    (0, class_transformer_1.Type)(() => output_1.Output, {
        discriminator: output_1.OutputDiscriminator,
    })
], Transaction.prototype, "outputs", void 0);
exports.Transaction = Transaction;
//# sourceMappingURL=transaction.js.map