// 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 { Signature, SignatureDiscriminator } from '../signature';
import { plainToInstance, Type } from 'class-transformer';
import { BlockBody } from './block-body';
import { BlockBodyDiscriminator } from '.';
/**
 * The block header.
 */
var BlockHeader = /** @class */ (function () {
    function BlockHeader(protocolVersion, networkId, issuingTime, slotCommitmentId, latestFinalizedSlot, issuerId) {
        this.protocolVersion = protocolVersion;
        this.networkId = networkId;
        this.issuingTime = issuingTime;
        this.slotCommitmentId = slotCommitmentId;
        this.latestFinalizedSlot = latestFinalizedSlot;
        this.issuerId = issuerId;
    }
    return BlockHeader;
}());
/**
 * Represent the object that nodes gossip around the network.
 */
var Block = /** @class */ (function () {
    function Block(header, body, signature) {
        this.header = header;
        this.body = body;
        this.signature = signature;
    }
    /**
     * Checks whether the block body is a `BasicBlockBody`.
     * @returns true if it is, otherwise false
     */
    Block.prototype.isBasic = function () {
        return this.body.isBasic();
    };
    /**
     * Gets the block body as an actual `BasicBlockBody`.
     * NOTE: Will throw an error if the block body is not a `BasicBlockBody`.
     * @returns The block
     */
    Block.prototype.asBasic = function () {
        return this.body.asBasic();
    };
    /**
     * Checks whether the block body is a `ValidationBlockBody`.
     * @returns true if it is, otherwise false
     */
    Block.prototype.isValidation = function () {
        return this.body.isValidation();
    };
    /**
     * Gets the block body as an actual `ValidationBlockBody`.
     * NOTE: Will throw an error if the block body is not a `ValidationBlockBody`.
     * @returns The block
     */
    Block.prototype.asValidation = function () {
        return this.body.asValidation();
    };
    /**
     * Returns the block id.
     */
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    Block.id = function (block, params) {
        // Implementation injected in lib/index.ts, as it uses bindings.
        return null;
    };
    __decorate([
        Type(function () { return BlockBody; }, {
            discriminator: BlockBodyDiscriminator
        })
    ], Block.prototype, "body");
    __decorate([
        Type(function () { return Signature; }, {
            discriminator: SignatureDiscriminator
        })
    ], Block.prototype, "signature");
    return Block;
}());
function parseBlock(data) {
    return plainToInstance(Block, data);
}
/**
 * Represent the object that nodes gossip around the network.
 */
var UnsignedBlock = /** @class */ (function () {
    function UnsignedBlock(protocolVersion, networkId, issuingTime, slotCommitmentId, latestFinalizedSlot, issuerId, body) {
        this.protocolVersion = protocolVersion;
        this.networkId = networkId;
        this.issuingTime = issuingTime;
        this.slotCommitmentId = slotCommitmentId;
        this.latestFinalizedSlot = latestFinalizedSlot;
        this.issuerId = issuerId;
        this.body = body;
    }
    /**
     * Checks whether the block body is a `BasicBlockBody`.
     * @returns true if it is, otherwise false
     */
    UnsignedBlock.prototype.isBasic = function () {
        return this.body.isBasic();
    };
    /**
     * Gets the block body as an actual `BasicBlock`.
     * NOTE: Will throw an error if the block body is not a `BasicBlockBody`.
     * @returns The BasicBlockBody
     */
    UnsignedBlock.prototype.asBasic = function () {
        return this.body.asBasic();
    };
    /**
     * Checks whether the block body is a `ValidationBlockBody`.
     * @returns true if it is, otherwise false
     */
    UnsignedBlock.prototype.isValidation = function () {
        return this.body.isValidation();
    };
    /**
     * Gets the block body as an actual `ValidationBlockBody`.
     * NOTE: Will throw an error if the block body is not a `ValidationBlockBody`.
     * @returns The ValidationBlockBody
     */
    UnsignedBlock.prototype.asValidation = function () {
        return this.body.asValidation();
    };
    __decorate([
        Type(function () { return BlockBody; }, {
            discriminator: BlockBodyDiscriminator
        })
    ], UnsignedBlock.prototype, "body");
    return UnsignedBlock;
}());
function parseUnsignedBlock(data) {
    return plainToInstance(UnsignedBlock, data);
}
export { Block, BlockHeader, parseBlock, UnsignedBlock, parseUnsignedBlock };
//# sourceMappingURL=block.js.map