"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.parseUnsignedBlock = exports.UnsignedBlock = exports.parseBlock = exports.BlockHeader = exports.Block = void 0;
const signature_1 = require("../signature");
const class_transformer_1 = require("class-transformer");
const block_body_1 = require("./block-body");
const _1 = require(".");
/**
 * The block header.
 */
class BlockHeader {
    constructor(protocolVersion, networkId, issuingTime, slotCommitmentId, latestFinalizedSlot, issuerId) {
        this.protocolVersion = protocolVersion;
        this.networkId = networkId;
        this.issuingTime = issuingTime;
        this.slotCommitmentId = slotCommitmentId;
        this.latestFinalizedSlot = latestFinalizedSlot;
        this.issuerId = issuerId;
    }
}
exports.BlockHeader = BlockHeader;
/**
 * Represent the object that nodes gossip around the network.
 */
class Block {
    constructor(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
     */
    isBasic() {
        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
     */
    asBasic() {
        return this.body.asBasic();
    }
    /**
     * Checks whether the block body is a `ValidationBlockBody`.
     * @returns true if it is, otherwise false
     */
    isValidation() {
        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
     */
    asValidation() {
        return this.body.asValidation();
    }
    /**
     * Returns the block id.
     */
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    static id(block, params) {
        // Implementation injected in lib/index.ts, as it uses bindings.
        return null;
    }
}
__decorate([
    (0, class_transformer_1.Type)(() => block_body_1.BlockBody, {
        discriminator: _1.BlockBodyDiscriminator,
    })
], Block.prototype, "body", void 0);
__decorate([
    (0, class_transformer_1.Type)(() => signature_1.Signature, {
        discriminator: signature_1.SignatureDiscriminator,
    })
], Block.prototype, "signature", void 0);
exports.Block = Block;
function parseBlock(data) {
    return (0, class_transformer_1.plainToInstance)(Block, data);
}
exports.parseBlock = parseBlock;
/**
 * Represent the object that nodes gossip around the network.
 */
class UnsignedBlock {
    constructor(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
     */
    isBasic() {
        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
     */
    asBasic() {
        return this.body.asBasic();
    }
    /**
     * Checks whether the block body is a `ValidationBlockBody`.
     * @returns true if it is, otherwise false
     */
    isValidation() {
        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
     */
    asValidation() {
        return this.body.asValidation();
    }
}
__decorate([
    (0, class_transformer_1.Type)(() => block_body_1.BlockBody, {
        discriminator: _1.BlockBodyDiscriminator,
    })
], UnsignedBlock.prototype, "body", void 0);
exports.UnsignedBlock = UnsignedBlock;
function parseUnsignedBlock(data) {
    return (0, class_transformer_1.plainToInstance)(UnsignedBlock, data);
}
exports.parseUnsignedBlock = parseUnsignedBlock;
//# sourceMappingURL=block.js.map