"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _util = require("@polkadot/util");

var _create = require("./create");

var _AbstractInt = _interopRequireWildcard(require("./AbstractInt"));

// Copyright 2017-2019 @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.

/**
 * @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.default {
  constructor() {
    let value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
    let bitLength = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _AbstractInt.DEFAULT_UINT_BITS;
    let isHexJson = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
    super(false, value, bitLength, isHexJson);
  }
  /**
   * @description Returns a hex string representation of the value
   */


  toHex() {
    let isLe = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
    // For display/JSON, this is BE, for compare, use isLe
    return (0, _util.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 (0, _create.ClassOf)('Balance') ? 'Balance' : "u".concat(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 (0, _util.bnToU8a)(this, {
      bitLength: this._bitLength,
      isLe: true,
      isNegative: false
    });
  }

}

exports.default = UInt;