"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.BountyStateSDKType = exports.BountyStateAmino = exports.BountyState = exports.BountyParentSDKType = exports.BountyParentAmino = exports.BountyParent = exports.Bounty = void 0;
exports.bountyParentFromJSON = bountyParentFromJSON;
exports.bountyParentToJSON = bountyParentToJSON;
exports.bountyStateFromJSON = bountyStateFromJSON;
exports.bountyStateToJSON = bountyStateToJSON;
var _coin = require("../cosmos/base/v1beta1/coin");
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; }
var BountyState = exports.BountyState = /*#__PURE__*/function (BountyState) {
  BountyState[BountyState["BOUNTY_STATE_SRCDEBITTED"] = 0] = "BOUNTY_STATE_SRCDEBITTED";
  BountyState[BountyState["BOUNTY_STATE_DESTCREDITED"] = 1] = "BOUNTY_STATE_DESTCREDITED";
  BountyState[BountyState["BOUNTY_STATE_REVERTEDBACK"] = 2] = "BOUNTY_STATE_REVERTEDBACK";
  BountyState[BountyState["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
  return BountyState;
}({});
var BountyStateSDKType = exports.BountyStateSDKType = BountyState;
var BountyStateAmino = exports.BountyStateAmino = BountyState;
function bountyStateFromJSON(object) {
  switch (object) {
    case 0:
    case "BOUNTY_STATE_SRCDEBITTED":
      return BountyState.BOUNTY_STATE_SRCDEBITTED;
    case 1:
    case "BOUNTY_STATE_DESTCREDITED":
      return BountyState.BOUNTY_STATE_DESTCREDITED;
    case 2:
    case "BOUNTY_STATE_REVERTEDBACK":
      return BountyState.BOUNTY_STATE_REVERTEDBACK;
    case -1:
    case "UNRECOGNIZED":
    default:
      return BountyState.UNRECOGNIZED;
  }
}
function bountyStateToJSON(object) {
  switch (object) {
    case BountyState.BOUNTY_STATE_SRCDEBITTED:
      return "BOUNTY_STATE_SRCDEBITTED";
    case BountyState.BOUNTY_STATE_DESTCREDITED:
      return "BOUNTY_STATE_DESTCREDITED";
    case BountyState.BOUNTY_STATE_REVERTEDBACK:
      return "BOUNTY_STATE_REVERTEDBACK";
    case BountyState.UNRECOGNIZED:
    default:
      return "UNRECOGNIZED";
  }
}
var BountyParent = exports.BountyParent = /*#__PURE__*/function (BountyParent) {
  BountyParent[BountyParent["BOUNTY_PARENT_ISSUE"] = 0] = "BOUNTY_PARENT_ISSUE";
  BountyParent[BountyParent["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
  return BountyParent;
}({});
var BountyParentSDKType = exports.BountyParentSDKType = BountyParent;
var BountyParentAmino = exports.BountyParentAmino = BountyParent;
function bountyParentFromJSON(object) {
  switch (object) {
    case 0:
    case "BOUNTY_PARENT_ISSUE":
      return BountyParent.BOUNTY_PARENT_ISSUE;
    case -1:
    case "UNRECOGNIZED":
    default:
      return BountyParent.UNRECOGNIZED;
  }
}
function bountyParentToJSON(object) {
  switch (object) {
    case BountyParent.BOUNTY_PARENT_ISSUE:
      return "BOUNTY_PARENT_ISSUE";
    case BountyParent.UNRECOGNIZED:
    default:
      return "UNRECOGNIZED";
  }
}
function createBaseBounty() {
  return {
    id: BigInt(0),
    amount: [],
    state: 0,
    repositoryId: BigInt(0),
    parentIid: BigInt(0),
    parent: 0,
    expireAt: BigInt(0),
    rewardedTo: "",
    createdAt: BigInt(0),
    updatedAt: BigInt(0),
    creator: ""
  };
}
var Bounty = exports.Bounty = {
  typeUrl: "/gitopia.gitopia.gitopia.Bounty",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.id !== BigInt(0)) {
      writer.uint32(8).uint64(message.id);
    }
    var _iterator = _createForOfIteratorHelper(message.amount),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var v = _step.value;
        _coin.Coin.encode(v, writer.uint32(18).fork()).ldelim();
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    if (message.state !== 0) {
      writer.uint32(24).int32(message.state);
    }
    if (message.repositoryId !== BigInt(0)) {
      writer.uint32(32).uint64(message.repositoryId);
    }
    if (message.parentIid !== BigInt(0)) {
      writer.uint32(40).uint64(message.parentIid);
    }
    if (message.parent !== 0) {
      writer.uint32(48).int32(message.parent);
    }
    if (message.expireAt !== BigInt(0)) {
      writer.uint32(56).int64(message.expireAt);
    }
    if (message.rewardedTo !== "") {
      writer.uint32(66).string(message.rewardedTo);
    }
    if (message.createdAt !== BigInt(0)) {
      writer.uint32(72).int64(message.createdAt);
    }
    if (message.updatedAt !== BigInt(0)) {
      writer.uint32(80).int64(message.updatedAt);
    }
    if (message.creator !== "") {
      writer.uint32(90).string(message.creator);
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      id: (0, _helpers.isSet)(object.id) ? BigInt(object.id.toString()) : BigInt(0),
      amount: Array.isArray(object === null || object === void 0 ? void 0 : object.amount) ? object.amount.map(function (e) {
        return _coin.Coin.fromJSON(e);
      }) : [],
      state: (0, _helpers.isSet)(object.state) ? bountyStateFromJSON(object.state) : -1,
      repositoryId: (0, _helpers.isSet)(object.repositoryId) ? BigInt(object.repositoryId.toString()) : BigInt(0),
      parentIid: (0, _helpers.isSet)(object.parentIid) ? BigInt(object.parentIid.toString()) : BigInt(0),
      parent: (0, _helpers.isSet)(object.parent) ? bountyParentFromJSON(object.parent) : -1,
      expireAt: (0, _helpers.isSet)(object.expireAt) ? BigInt(object.expireAt.toString()) : BigInt(0),
      rewardedTo: (0, _helpers.isSet)(object.rewardedTo) ? String(object.rewardedTo) : "",
      createdAt: (0, _helpers.isSet)(object.createdAt) ? BigInt(object.createdAt.toString()) : BigInt(0),
      updatedAt: (0, _helpers.isSet)(object.updatedAt) ? BigInt(object.updatedAt.toString()) : BigInt(0),
      creator: (0, _helpers.isSet)(object.creator) ? String(object.creator) : ""
    };
  },
  fromPartial: function fromPartial(object) {
    var _object$amount, _object$state, _object$parent, _object$rewardedTo, _object$creator;
    var message = createBaseBounty();
    message.id = object.id !== undefined && object.id !== null ? BigInt(object.id.toString()) : BigInt(0);
    message.amount = ((_object$amount = object.amount) === null || _object$amount === void 0 ? void 0 : _object$amount.map(function (e) {
      return _coin.Coin.fromPartial(e);
    })) || [];
    message.state = (_object$state = object.state) !== null && _object$state !== void 0 ? _object$state : 0;
    message.repositoryId = object.repositoryId !== undefined && object.repositoryId !== null ? BigInt(object.repositoryId.toString()) : BigInt(0);
    message.parentIid = object.parentIid !== undefined && object.parentIid !== null ? BigInt(object.parentIid.toString()) : BigInt(0);
    message.parent = (_object$parent = object.parent) !== null && _object$parent !== void 0 ? _object$parent : 0;
    message.expireAt = object.expireAt !== undefined && object.expireAt !== null ? BigInt(object.expireAt.toString()) : BigInt(0);
    message.rewardedTo = (_object$rewardedTo = object.rewardedTo) !== null && _object$rewardedTo !== void 0 ? _object$rewardedTo : "";
    message.createdAt = object.createdAt !== undefined && object.createdAt !== null ? BigInt(object.createdAt.toString()) : BigInt(0);
    message.updatedAt = object.updatedAt !== undefined && object.updatedAt !== null ? BigInt(object.updatedAt.toString()) : BigInt(0);
    message.creator = (_object$creator = object.creator) !== null && _object$creator !== void 0 ? _object$creator : "";
    return message;
  },
  fromAmino: function fromAmino(object) {
    var _object$amount2;
    var message = createBaseBounty();
    if (object.id !== undefined && object.id !== null) {
      message.id = BigInt(object.id);
    }
    message.amount = ((_object$amount2 = object.amount) === null || _object$amount2 === void 0 ? void 0 : _object$amount2.map(function (e) {
      return _coin.Coin.fromAmino(e);
    })) || [];
    if (object.state !== undefined && object.state !== null) {
      message.state = object.state;
    }
    if (object.repositoryId !== undefined && object.repositoryId !== null) {
      message.repositoryId = BigInt(object.repositoryId);
    }
    if (object.parentIid !== undefined && object.parentIid !== null) {
      message.parentIid = BigInt(object.parentIid);
    }
    if (object.parent !== undefined && object.parent !== null) {
      message.parent = object.parent;
    }
    if (object.expireAt !== undefined && object.expireAt !== null) {
      message.expireAt = BigInt(object.expireAt);
    }
    if (object.rewardedTo !== undefined && object.rewardedTo !== null) {
      message.rewardedTo = object.rewardedTo;
    }
    if (object.createdAt !== undefined && object.createdAt !== null) {
      message.createdAt = BigInt(object.createdAt);
    }
    if (object.updatedAt !== undefined && object.updatedAt !== null) {
      message.updatedAt = BigInt(object.updatedAt);
    }
    if (object.creator !== undefined && object.creator !== null) {
      message.creator = object.creator;
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.id = message.id !== BigInt(0) ? message.id.toString() : undefined;
    if (message.amount) {
      obj.amount = message.amount.map(function (e) {
        return e ? _coin.Coin.toAmino(e) : undefined;
      });
    } else {
      obj.amount = message.amount;
    }
    obj.state = message.state === 0 ? undefined : message.state;
    obj.repositoryId = message.repositoryId !== BigInt(0) ? message.repositoryId.toString() : undefined;
    obj.parentIid = message.parentIid !== BigInt(0) ? message.parentIid.toString() : undefined;
    obj.parent = message.parent === 0 ? undefined : message.parent;
    obj.expireAt = message.expireAt !== BigInt(0) ? message.expireAt.toString() : undefined;
    obj.rewardedTo = message.rewardedTo === "" ? undefined : message.rewardedTo;
    obj.createdAt = message.createdAt !== BigInt(0) ? message.createdAt.toString() : undefined;
    obj.updatedAt = message.updatedAt !== BigInt(0) ? message.updatedAt.toString() : undefined;
    obj.creator = message.creator === "" ? undefined : message.creator;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return Bounty.fromAmino(object.value);
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return Bounty.decode(message.value);
  },
  toProto: function toProto(message) {
    return Bounty.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.gitopia.Bounty",
      value: Bounty.encode(message).finish()
    };
  }
};