"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 __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
    result["default"] = mod;
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const util_1 = require("@polkadot/util");
const createClass_1 = require("./create/createClass");
const AbstractInt_1 = __importStar(require("./AbstractInt"));
/**
 * @name UInt
 * @description
 * A generic unsigned integer codec. For Substrate all numbers are Little Endian encoded,
 * this handles the encoding and decoding of those numbers. Upon construction
 * the bitLength is provided and any additional use keeps the number to this
 * length. This extends `BN`, so all methods available on a normal `BN` object
 * is available here.
 * @noInheritDoc
 */
class UInt extends AbstractInt_1.default {
    constructor(registry, value = 0, bitLength = AbstractInt_1.DEFAULT_UINT_BITS, isHexJson = false) {
        super(registry, false, value, bitLength, isHexJson);
    }
    static with(bitLength) {
        return class extends UInt {
            constructor(registry, value) {
                super(registry, value, bitLength);
            }
        };
    }
    /**
     * @description Returns a hex string representation of the value
     */
    toHex(isLe = false) {
        // For display/JSON, this is BE, for compare, use isLe
        return util_1.bnToHex(this, {
            bitLength: this._bitLength,
            isLe,
            isNegative: false
        });
    }
    /**
     * @description Returns the base runtime type name for this instance
     */
    toRawType() {
        // NOTE In the case of balances, which have a special meaning on the UI
        // and can be interpreted differently, return a specific value for it so
        // underlying it always matches (no matter which length it actually is)
        return this instanceof createClass_1.ClassOf(this.registry, 'Balance')
            ? 'Balance'
            : `u${this._bitLength}`;
    }
    /**
     * @description Encodes the value as a Uint8Array as per the SCALE specifications
     * @param isBare true when the value has none of the type-specific prefixes (internal)
     */
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    toU8a(isBare) {
        return util_1.bnToU8a(this, {
            bitLength: this._bitLength,
            isLe: true,
            isNegative: false
        });
    }
}
exports.default = UInt;
