import Long  from 'long';
import includeIoMixin from './io-mixin';

export class UnsignedHyper extends Long {
  static read(io) {
    let high = io.readInt32BE();
    let low  = io.readInt32BE();
    return this.fromBits(low, high);
  }

  static write(value, io) {
    if(!(value instanceof this)) {
      throw new Error(
        `XDR Write Error: ${value} is not an UnsignedHyper`
      );
    }

    io.writeInt32BE(value.high);
    io.writeInt32BE(value.low);
  }

  static fromString(string) {
    let result = super.fromString(string, true);
    return new this(result.low, result.high);
  }

  static fromBits(low, high) {
    let result = super.fromBits(low, high, true);
    return new this(result.low, result.high);
  }

  static isValid(value) {
    return value instanceof this;
  }

  constructor(low, high) {
    super(low, high, false);
  }
}

includeIoMixin(UnsignedHyper);

UnsignedHyper.MAX_VALUE = new UnsignedHyper(
  Long.MAX_UNSIGNED_VALUE.low, 
  Long.MAX_UNSIGNED_VALUE.high
);

UnsignedHyper.MIN_VALUE = new UnsignedHyper(
  Long.MIN_VALUE.low, 
  Long.MIN_VALUE.high
);

@@ -842,12 +842,11 @@
 gh, 
-fals
+tru
 e);%0A
@@ -951,33 +951,32 @@
 IGNED_VALUE.low,
- 
 %0A  Long.MAX_UNSI
@@ -1061,17 +1061,16 @@
 LUE.low,
- 
 %0A  Long.

Mark unsigned hyper as unsigned