//@ts-nocheck
import { AccountAuthenticator } from "./models";
import { Params } from "./params";
import { Long, isSet } from "../../../helpers";
import * as _m0 from "protobufjs/minimal";
/**
 * AuthenticatorData represents a genesis exported account with Authenticators.
 * The address is used as the key, and the account authenticators are stored in
 * the authenticators field.
 */

/**
 * AuthenticatorData represents a genesis exported account with Authenticators.
 * The address is used as the key, and the account authenticators are stored in
 * the authenticators field.
 */

/** GenesisState defines the authenticator module's genesis state. */

/** GenesisState defines the authenticator module's genesis state. */

function createBaseAuthenticatorData() {
  return {
    address: "",
    authenticators: []
  };
}
export const AuthenticatorData = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.address !== "") {
      writer.uint32(10).string(message.address);
    }
    for (const v of message.authenticators) {
      AccountAuthenticator.encode(v, writer.uint32(18).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseAuthenticatorData();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.address = reader.string();
          break;
        case 2:
          message.authenticators.push(AccountAuthenticator.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON(object) {
    return {
      address: isSet(object.address) ? String(object.address) : "",
      authenticators: Array.isArray(object === null || object === void 0 ? void 0 : object.authenticators) ? object.authenticators.map(e => AccountAuthenticator.fromJSON(e)) : []
    };
  },
  toJSON(message) {
    const obj = {};
    message.address !== undefined && (obj.address = message.address);
    if (message.authenticators) {
      obj.authenticators = message.authenticators.map(e => e ? AccountAuthenticator.toJSON(e) : undefined);
    } else {
      obj.authenticators = [];
    }
    return obj;
  },
  fromPartial(object) {
    var _object$address, _object$authenticator;
    const message = createBaseAuthenticatorData();
    message.address = (_object$address = object.address) !== null && _object$address !== void 0 ? _object$address : "";
    message.authenticators = ((_object$authenticator = object.authenticators) === null || _object$authenticator === void 0 ? void 0 : _object$authenticator.map(e => AccountAuthenticator.fromPartial(e))) || [];
    return message;
  }
};
function createBaseGenesisState() {
  return {
    params: undefined,
    nextAuthenticatorId: Long.UZERO,
    authenticatorData: []
  };
}
export const GenesisState = {
  encode(message, writer = _m0.Writer.create()) {
    if (message.params !== undefined) {
      Params.encode(message.params, writer.uint32(10).fork()).ldelim();
    }
    if (!message.nextAuthenticatorId.isZero()) {
      writer.uint32(16).uint64(message.nextAuthenticatorId);
    }
    for (const v of message.authenticatorData) {
      AuthenticatorData.encode(v, writer.uint32(26).fork()).ldelim();
    }
    return writer;
  },
  decode(input, length) {
    const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    let end = length === undefined ? reader.len : reader.pos + length;
    const message = createBaseGenesisState();
    while (reader.pos < end) {
      const tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.params = Params.decode(reader, reader.uint32());
          break;
        case 2:
          message.nextAuthenticatorId = reader.uint64();
          break;
        case 3:
          message.authenticatorData.push(AuthenticatorData.decode(reader, reader.uint32()));
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON(object) {
    return {
      params: isSet(object.params) ? Params.fromJSON(object.params) : undefined,
      nextAuthenticatorId: isSet(object.nextAuthenticatorId) ? Long.fromValue(object.nextAuthenticatorId) : Long.UZERO,
      authenticatorData: Array.isArray(object === null || object === void 0 ? void 0 : object.authenticatorData) ? object.authenticatorData.map(e => AuthenticatorData.fromJSON(e)) : []
    };
  },
  toJSON(message) {
    const obj = {};
    message.params !== undefined && (obj.params = message.params ? Params.toJSON(message.params) : undefined);
    message.nextAuthenticatorId !== undefined && (obj.nextAuthenticatorId = (message.nextAuthenticatorId || Long.UZERO).toString());
    if (message.authenticatorData) {
      obj.authenticatorData = message.authenticatorData.map(e => e ? AuthenticatorData.toJSON(e) : undefined);
    } else {
      obj.authenticatorData = [];
    }
    return obj;
  },
  fromPartial(object) {
    var _object$authenticator2;
    const message = createBaseGenesisState();
    message.params = object.params !== undefined && object.params !== null ? Params.fromPartial(object.params) : undefined;
    message.nextAuthenticatorId = object.nextAuthenticatorId !== undefined && object.nextAuthenticatorId !== null ? Long.fromValue(object.nextAuthenticatorId) : Long.UZERO;
    message.authenticatorData = ((_object$authenticator2 = object.authenticatorData) === null || _object$authenticator2 === void 0 ? void 0 : _object$authenticator2.map(e => AuthenticatorData.fromPartial(e))) || [];
    return message;
  }
};