"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 sanitize_1 = __importDefault(require("../codec/create/sanitize"));
const Text_1 = __importDefault(require("./Text"));
/**
 * @name Type
 * @description
 * This is a extended version of String, specifically to handle types. Here we rely fully
 * on what string provides us, however we also adjust the types received from the runtime,
 * i.e. we remove the `T::` prefixes found in some types for consistency across implementation.
 */
class Type extends Text_1.default {
    constructor(registry, value = '') {
        // First decode it with Text
        const textValue = new Text_1.default(registry, value);
        // Then cleanup the textValue to get the @polkadot/types type, and pass the
        // sanitized value to constructor
        super(registry, sanitize_1.default(textValue.toString()));
        this._originalLength = textValue.encodedLength;
    }
    /**
     * @description The length of the value when encoded as a Uint8Array
     */
    get encodedLength() {
        // NOTE Length is used in the decoding calculations, so return the original (pre-cleanup)
        // length of the data. Since toU8a is disabled, this does not affect encoding, but rather
        // only the decoding leg, allowing the decoders to work with original pointers
        return this._originalLength;
    }
    /**
     * @description Returns the base runtime type name for this instance
     */
    toRawType() {
        return 'Type';
    }
}
exports.default = Type;
