"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.TableDescriptor = exports.SingletonDescriptor = exports.SecondaryIndexDescriptor = exports.PrimaryKeyDescriptor = void 0;
var _binary = require("../../../binary");
var _helpers = require("../../../helpers");
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
/** TableDescriptor describes an ORM table. */

/** TableDescriptor describes an ORM table. */

/** TableDescriptor describes an ORM table. */

/** PrimaryKeyDescriptor describes a table primary key. */

/** PrimaryKeyDescriptor describes a table primary key. */

/** PrimaryKeyDescriptor describes a table primary key. */

/** PrimaryKeyDescriptor describes a table secondary index. */

/** PrimaryKeyDescriptor describes a table secondary index. */

/** PrimaryKeyDescriptor describes a table secondary index. */

/** TableDescriptor describes an ORM singleton table which has at most one instance. */

/** TableDescriptor describes an ORM singleton table which has at most one instance. */

/** TableDescriptor describes an ORM singleton table which has at most one instance. */

function createBaseTableDescriptor() {
  return {
    primaryKey: undefined,
    index: [],
    id: 0
  };
}
var TableDescriptor = exports.TableDescriptor = {
  typeUrl: "/cosmos.orm.v1.TableDescriptor",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.primaryKey !== undefined) {
      PrimaryKeyDescriptor.encode(message.primaryKey, writer.uint32(10).fork()).ldelim();
    }
    var _iterator = _createForOfIteratorHelper(message.index),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var v = _step.value;
        SecondaryIndexDescriptor.encode(v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    if (message.id !== 0) {
      writer.uint32(24).uint32(message.id);
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      primaryKey: (0, _helpers.isSet)(object.primaryKey) ? PrimaryKeyDescriptor.fromJSON(object.primaryKey) : undefined,
      index: Array.isArray(object === null || object === void 0 ? void 0 : object.index) ? object.index.map(function (e) {
        return SecondaryIndexDescriptor.fromJSON(e);
      }) : [],
      id: (0, _helpers.isSet)(object.id) ? Number(object.id) : 0
    };
  },
  fromPartial: function fromPartial(object) {
    var _object$index, _object$id;
    var message = createBaseTableDescriptor();
    message.primaryKey = object.primaryKey !== undefined && object.primaryKey !== null ? PrimaryKeyDescriptor.fromPartial(object.primaryKey) : undefined;
    message.index = ((_object$index = object.index) === null || _object$index === void 0 ? void 0 : _object$index.map(function (e) {
      return SecondaryIndexDescriptor.fromPartial(e);
    })) || [];
    message.id = (_object$id = object.id) !== null && _object$id !== void 0 ? _object$id : 0;
    return message;
  },
  fromAmino: function fromAmino(object) {
    var _object$index2;
    var message = createBaseTableDescriptor();
    if (object.primary_key !== undefined && object.primary_key !== null) {
      message.primaryKey = PrimaryKeyDescriptor.fromAmino(object.primary_key);
    }
    message.index = ((_object$index2 = object.index) === null || _object$index2 === void 0 ? void 0 : _object$index2.map(function (e) {
      return SecondaryIndexDescriptor.fromAmino(e);
    })) || [];
    if (object.id !== undefined && object.id !== null) {
      message.id = object.id;
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.primary_key = message.primaryKey ? PrimaryKeyDescriptor.toAmino(message.primaryKey) : undefined;
    if (message.index) {
      obj.index = message.index.map(function (e) {
        return e ? SecondaryIndexDescriptor.toAmino(e) : undefined;
      });
    } else {
      obj.index = message.index;
    }
    obj.id = message.id === 0 ? undefined : message.id;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return TableDescriptor.fromAmino(object.value);
  },
  toAminoMsg: function toAminoMsg(message) {
    return {
      type: "cosmos-sdk/TableDescriptor",
      value: TableDescriptor.toAmino(message)
    };
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return TableDescriptor.decode(message.value);
  },
  toProto: function toProto(message) {
    return TableDescriptor.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/cosmos.orm.v1.TableDescriptor",
      value: TableDescriptor.encode(message).finish()
    };
  }
};
function createBasePrimaryKeyDescriptor() {
  return {
    fields: "",
    autoIncrement: false
  };
}
var PrimaryKeyDescriptor = exports.PrimaryKeyDescriptor = {
  typeUrl: "/cosmos.orm.v1.PrimaryKeyDescriptor",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.fields !== "") {
      writer.uint32(10).string(message.fields);
    }
    if (message.autoIncrement === true) {
      writer.uint32(16).bool(message.autoIncrement);
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      fields: (0, _helpers.isSet)(object.fields) ? String(object.fields) : "",
      autoIncrement: (0, _helpers.isSet)(object.autoIncrement) ? Boolean(object.autoIncrement) : false
    };
  },
  fromPartial: function fromPartial(object) {
    var _object$fields, _object$autoIncrement;
    var message = createBasePrimaryKeyDescriptor();
    message.fields = (_object$fields = object.fields) !== null && _object$fields !== void 0 ? _object$fields : "";
    message.autoIncrement = (_object$autoIncrement = object.autoIncrement) !== null && _object$autoIncrement !== void 0 ? _object$autoIncrement : false;
    return message;
  },
  fromAmino: function fromAmino(object) {
    var message = createBasePrimaryKeyDescriptor();
    if (object.fields !== undefined && object.fields !== null) {
      message.fields = object.fields;
    }
    if (object.auto_increment !== undefined && object.auto_increment !== null) {
      message.autoIncrement = object.auto_increment;
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.fields = message.fields === "" ? undefined : message.fields;
    obj.auto_increment = message.autoIncrement === false ? undefined : message.autoIncrement;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return PrimaryKeyDescriptor.fromAmino(object.value);
  },
  toAminoMsg: function toAminoMsg(message) {
    return {
      type: "cosmos-sdk/PrimaryKeyDescriptor",
      value: PrimaryKeyDescriptor.toAmino(message)
    };
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return PrimaryKeyDescriptor.decode(message.value);
  },
  toProto: function toProto(message) {
    return PrimaryKeyDescriptor.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/cosmos.orm.v1.PrimaryKeyDescriptor",
      value: PrimaryKeyDescriptor.encode(message).finish()
    };
  }
};
function createBaseSecondaryIndexDescriptor() {
  return {
    fields: "",
    id: 0,
    unique: false
  };
}
var SecondaryIndexDescriptor = exports.SecondaryIndexDescriptor = {
  typeUrl: "/cosmos.orm.v1.SecondaryIndexDescriptor",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.fields !== "") {
      writer.uint32(10).string(message.fields);
    }
    if (message.id !== 0) {
      writer.uint32(16).uint32(message.id);
    }
    if (message.unique === true) {
      writer.uint32(24).bool(message.unique);
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      fields: (0, _helpers.isSet)(object.fields) ? String(object.fields) : "",
      id: (0, _helpers.isSet)(object.id) ? Number(object.id) : 0,
      unique: (0, _helpers.isSet)(object.unique) ? Boolean(object.unique) : false
    };
  },
  fromPartial: function fromPartial(object) {
    var _object$fields2, _object$id2, _object$unique;
    var message = createBaseSecondaryIndexDescriptor();
    message.fields = (_object$fields2 = object.fields) !== null && _object$fields2 !== void 0 ? _object$fields2 : "";
    message.id = (_object$id2 = object.id) !== null && _object$id2 !== void 0 ? _object$id2 : 0;
    message.unique = (_object$unique = object.unique) !== null && _object$unique !== void 0 ? _object$unique : false;
    return message;
  },
  fromAmino: function fromAmino(object) {
    var message = createBaseSecondaryIndexDescriptor();
    if (object.fields !== undefined && object.fields !== null) {
      message.fields = object.fields;
    }
    if (object.id !== undefined && object.id !== null) {
      message.id = object.id;
    }
    if (object.unique !== undefined && object.unique !== null) {
      message.unique = object.unique;
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.fields = message.fields === "" ? undefined : message.fields;
    obj.id = message.id === 0 ? undefined : message.id;
    obj.unique = message.unique === false ? undefined : message.unique;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return SecondaryIndexDescriptor.fromAmino(object.value);
  },
  toAminoMsg: function toAminoMsg(message) {
    return {
      type: "cosmos-sdk/SecondaryIndexDescriptor",
      value: SecondaryIndexDescriptor.toAmino(message)
    };
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return SecondaryIndexDescriptor.decode(message.value);
  },
  toProto: function toProto(message) {
    return SecondaryIndexDescriptor.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/cosmos.orm.v1.SecondaryIndexDescriptor",
      value: SecondaryIndexDescriptor.encode(message).finish()
    };
  }
};
function createBaseSingletonDescriptor() {
  return {
    id: 0
  };
}
var SingletonDescriptor = exports.SingletonDescriptor = {
  typeUrl: "/cosmos.orm.v1.SingletonDescriptor",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.id !== 0) {
      writer.uint32(8).uint32(message.id);
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      id: (0, _helpers.isSet)(object.id) ? Number(object.id) : 0
    };
  },
  fromPartial: function fromPartial(object) {
    var _object$id3;
    var message = createBaseSingletonDescriptor();
    message.id = (_object$id3 = object.id) !== null && _object$id3 !== void 0 ? _object$id3 : 0;
    return message;
  },
  fromAmino: function fromAmino(object) {
    var message = createBaseSingletonDescriptor();
    if (object.id !== undefined && object.id !== null) {
      message.id = object.id;
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.id = message.id === 0 ? undefined : message.id;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return SingletonDescriptor.fromAmino(object.value);
  },
  toAminoMsg: function toAminoMsg(message) {
    return {
      type: "cosmos-sdk/SingletonDescriptor",
      value: SingletonDescriptor.toAmino(message)
    };
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return SingletonDescriptor.decode(message.value);
  },
  toProto: function toProto(message) {
    return SingletonDescriptor.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/cosmos.orm.v1.SingletonDescriptor",
      value: SingletonDescriptor.encode(message).finish()
    };
  }
};