"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 Option_1 = __importDefault(require("./Option"));
const Struct_1 = __importDefault(require("./Struct"));
const Tuple_1 = __importDefault(require("./Tuple"));
const Vec_1 = __importDefault(require("./Vec"));
const EMPTY = new Uint8Array();
/**
 * @name Linkage
 * @description The wrapper for the result from a LinkedMap
 */
class Linkage extends Struct_1.default {
    constructor(registry, Type, value) {
        super(registry, {
            previous: Option_1.default.with(Type),
            next: Option_1.default.with(Type)
        }, value);
    }
    static withKey(Type) {
        return class extends Linkage {
            constructor(registry, value) {
                super(registry, Type, value);
            }
        };
    }
    get previous() {
        return this.get('previous');
    }
    get next() {
        return this.get('next');
    }
    /**
     * @description Returns the base runtime type name for this instance
     */
    toRawType() {
        return `Linkage<${this.next.toRawType(true)}>`;
    }
    /**
     * @description Custom toU8a which with bare mode does not return the linkage if empty
     */
    toU8a() {
        // As part of a storage query (where these appear), in the case of empty, the values
        // are NOT populated by the node - follow the same logic, leaving it empty
        return this.isEmpty
            ? EMPTY
            : super.toU8a();
    }
}
exports.default = Linkage;
/**
 * @name LinkageResult
 * @description A Linkage keys/Values tuple
 */
class LinkageResult extends Tuple_1.default {
    constructor(registry, [TypeKey, keys], [TypeValue, values]) {
        super(registry, {
            Keys: Vec_1.default.with(TypeKey),
            Values: Vec_1.default.with(TypeValue)
        }, [keys, values]);
    }
}
exports.LinkageResult = LinkageResult;
