// Generated by nautilus-codegen. Do not edit manually.

function _toVectorArray(value = []) {
  if (value instanceof Vector) return value.toList();
  if (
    value != null
    && typeof value === 'object'
    && !Array.isArray(value)
    && Object.prototype.hasOwnProperty.call(value, 'values')
  ) {
    return _toVectorArray(value.values);
  }
  return Array.from(value, item => Number(item));
}

export class Vector {
  constructor(value) {
    this.value = _toVectorArray(value);
  }

  static empty() {
    return new Vector([]);
  }

  static of(...values) {
    return new Vector(values);
  }

  static from(value) {
    return value instanceof Vector ? value : new Vector(value);
  }

  static toWireInput(value) {
    return _toVectorArray(value);
  }

  toList() {
    return [...this.value];
  }

  toWire() {
    return this.toList();
  }

  at(index) {
    return this.value[index];
  }

  isEmpty() {
    return this.value.length === 0;
  }

  concat(other) {
    const otherValue = other instanceof Vector ? other.value : _toVectorArray(other);
    return new Vector([...this.value, ...otherValue]);
  }

  equals(other) {
    const otherValue = other instanceof Vector ? other.value : _toVectorArray(other);
    return this.value.length === otherValue.length && this.value.every((item, index) => item === otherValue[index]);
  }

  [Symbol.iterator]() {
    return this.value[Symbol.iterator]();
  }

  get length() {
    return this.value.length;
  }
}
