"use strict";
// Copyright 2017-2020 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("@polkadot/util");
const Enum_1 = __importDefault(require("../../codec/Enum"));
const Struct_1 = __importDefault(require("../../codec/Struct"));
const Vec_1 = __importDefault(require("../../codec/Vec"));
/**
 * @name DigestItem
 * @description
 * A [[Enum]] the specifies the specific item in the logs of a [[Digest]]
 */
class DigestItem extends Enum_1.default {
    constructor(registry, value) {
        super(registry, {
            Other: 'Bytes',
            AuthoritiesChange: 'Vec<AuthorityId>',
            ChangesTrieRoot: 'Hash',
            SealV0: 'SealV0',
            Consensus: 'Consensus',
            Seal: 'Seal',
            PreRuntime: 'PreRuntime' // 6
        }, value);
    }
    /**
     * @description Returns the item as a [[Vec<AuthorityId>]]
     */
    get asAuthoritiesChange() {
        util_1.assert(this.isAuthoritiesChange, `Cannot convert '${this.type}' via asAuthoritiesChange`);
        return this.value;
    }
    /**
     * @description Returns the item as a [[ChangesTrieRoot]]
     */
    get asChangesTrieRoot() {
        util_1.assert(this.isChangesTrieRoot, `Cannot convert '${this.type}' via asChangesTrieRoot`);
        return this.value;
    }
    /**
     * @desciption Retuns the item as a [[Consensus]]
     */
    get asConsensus() {
        util_1.assert(this.isConsensus, `Cannot convert '${this.type}' via asConsensus`);
        return this.value;
    }
    /**
     * @description Returns the item as a [[Bytes]]
     */
    get asOther() {
        util_1.assert(this.isOther, `Cannot convert '${this.type}' via asOther`);
        return this.value;
    }
    /**
     * @description Returns the item as a [[PreRuntime]]
     */
    get asPreRuntime() {
        util_1.assert(this.isPreRuntime, `Cannot convert '${this.type}' via asPreRuntime`);
        return this.value;
    }
    /**
     * @description Returns the item as a [[Seal]]
     */
    get asSeal() {
        util_1.assert(this.isSeal, `Cannot convert '${this.type}' via asSeal`);
        return this.value;
    }
    /**
     * @description Returns the item as a [[SealV0]]
     */
    get asSealV0() {
        util_1.assert(this.isSealV0, `Cannot convert '${this.type}' via asSealV0`);
        return this.value;
    }
    /**
     * @description Returns true on [[AuthoritiesChange]]
     */
    get isAuthoritiesChange() {
        return this.type === 'AuthoritiesChange';
    }
    /**
     * @description Returns true on [[ChangesTrieRoot]]
     */
    get isChangesTrieRoot() {
        return this.type === 'ChangesTrieRoot';
    }
    /**
     * @description Returns true on [[Consensus]]
     */
    get isConsensus() {
        return this.type === 'Consensus';
    }
    /**
     * @description Returns true on [[Other]]
     */
    get isOther() {
        return this.type === 'Other';
    }
    /**
     * @description Returns true on [[PreRuntime]]
     */
    get isPreRuntime() {
        return this.type === 'PreRuntime';
    }
    /**
     * @description Returns true on [[Seal]]
     */
    get isSeal() {
        return this.type === 'Seal';
    }
    /**
     * @description Returns true on [[SealV0]]
     */
    get isSealV0() {
        return this.type === 'SealV0';
    }
    /**
     * @description Converts the Object to JSON, typically used for RPC transfers. For logs, we overrides to produce the hex version (sligning with substrate gives in actual JSON responses)
     */
    toJSON() {
        return this.toHex();
    }
    /**
     * @description Returns the type of engine
     */
    get type() {
        return super.type;
    }
}
exports.DigestItem = DigestItem;
/**
 * @name Digest
 * @description
 * A [[Header]] Digest
 */
class Digest extends Struct_1.default {
    constructor(registry, value) {
        super(registry, {
            logs: Vec_1.default.with(DigestItem)
        }, value);
    }
    /**
     * @description The [[DigestItem]] logs
     */
    get logs() {
        return this.get('logs');
    }
    /**
     * @description The [[DigestItem]] logs, filtered, filter items included. This is useful for derive functionality where only a certain type of log is to be returned.
     */
    logsWith(...include) {
        return this.logs.filter(({ type }) => include.includes(type));
    }
    /**
     * @description The [[DigestItem]] logs, filtered, filter items exluded. This is useful for stripping headers for eg. WASM runtime execution.
     */
    logsWithout(...exclude) {
        return this.logs.filter(({ type }) => !exclude.includes(type));
    }
}
exports.default = Digest;
