"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Issue_StateSDKType = exports.Issue_StateAmino = exports.Issue_State = exports.Issue = void 0;
exports.issue_StateFromJSON = issue_StateFromJSON;
exports.issue_StateToJSON = issue_StateToJSON;
var _repository = require("./repository");
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 Issue_State = exports.Issue_State = /*#__PURE__*/function (Issue_State) {
  Issue_State[Issue_State["OPEN"] = 0] = "OPEN";
  Issue_State[Issue_State["CLOSED"] = 1] = "CLOSED";
  Issue_State[Issue_State["UNRECOGNIZED"] = -1] = "UNRECOGNIZED";
  return Issue_State;
}({});
var Issue_StateSDKType = exports.Issue_StateSDKType = Issue_State;
var Issue_StateAmino = exports.Issue_StateAmino = Issue_State;
function issue_StateFromJSON(object) {
  switch (object) {
    case 0:
    case "OPEN":
      return Issue_State.OPEN;
    case 1:
    case "CLOSED":
      return Issue_State.CLOSED;
    case -1:
    case "UNRECOGNIZED":
    default:
      return Issue_State.UNRECOGNIZED;
  }
}
function issue_StateToJSON(object) {
  switch (object) {
    case Issue_State.OPEN:
      return "OPEN";
    case Issue_State.CLOSED:
      return "CLOSED";
    case Issue_State.UNRECOGNIZED:
    default:
      return "UNRECOGNIZED";
  }
}
function createBaseIssue() {
  return {
    creator: "",
    id: BigInt(0),
    iid: BigInt(0),
    title: "",
    state: 0,
    description: "",
    commentsCount: BigInt(0),
    pullRequests: [],
    repositoryId: BigInt(0),
    labels: [],
    weight: BigInt(0),
    assignees: [],
    bounties: [],
    createdAt: BigInt(0),
    updatedAt: BigInt(0),
    closedAt: BigInt(0),
    closedBy: ""
  };
}
var Issue = exports.Issue = {
  typeUrl: "/gitopia.gitopia.gitopia.Issue",
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _binary.BinaryWriter.create();
    if (message.creator !== "") {
      writer.uint32(10).string(message.creator);
    }
    if (message.id !== BigInt(0)) {
      writer.uint32(16).uint64(message.id);
    }
    if (message.iid !== BigInt(0)) {
      writer.uint32(24).uint64(message.iid);
    }
    if (message.title !== "") {
      writer.uint32(34).string(message.title);
    }
    if (message.state !== 0) {
      writer.uint32(40).int32(message.state);
    }
    if (message.description !== "") {
      writer.uint32(50).string(message.description);
    }
    if (message.commentsCount !== BigInt(0)) {
      writer.uint32(56).uint64(message.commentsCount);
    }
    var _iterator = _createForOfIteratorHelper(message.pullRequests),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var v = _step.value;
        _repository.PullRequestIid.encode(v, writer.uint32(66).fork()).ldelim();
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    if (message.repositoryId !== BigInt(0)) {
      writer.uint32(72).uint64(message.repositoryId);
    }
    writer.uint32(82).fork();
    var _iterator2 = _createForOfIteratorHelper(message.labels),
      _step2;
    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var _v = _step2.value;
        writer.uint64(_v);
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }
    writer.ldelim();
    if (message.weight !== BigInt(0)) {
      writer.uint32(88).uint64(message.weight);
    }
    var _iterator3 = _createForOfIteratorHelper(message.assignees),
      _step3;
    try {
      for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
        var _v2 = _step3.value;
        writer.uint32(98).string(_v2);
      }
    } catch (err) {
      _iterator3.e(err);
    } finally {
      _iterator3.f();
    }
    writer.uint32(106).fork();
    var _iterator4 = _createForOfIteratorHelper(message.bounties),
      _step4;
    try {
      for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
        var _v3 = _step4.value;
        writer.uint64(_v3);
      }
    } catch (err) {
      _iterator4.e(err);
    } finally {
      _iterator4.f();
    }
    writer.ldelim();
    if (message.createdAt !== BigInt(0)) {
      writer.uint32(112).int64(message.createdAt);
    }
    if (message.updatedAt !== BigInt(0)) {
      writer.uint32(120).int64(message.updatedAt);
    }
    if (message.closedAt !== BigInt(0)) {
      writer.uint32(128).int64(message.closedAt);
    }
    if (message.closedBy !== "") {
      writer.uint32(138).string(message.closedBy);
    }
    return writer;
  },
  fromJSON: function fromJSON(object) {
    return {
      creator: (0, _helpers.isSet)(object.creator) ? String(object.creator) : "",
      id: (0, _helpers.isSet)(object.id) ? BigInt(object.id.toString()) : BigInt(0),
      iid: (0, _helpers.isSet)(object.iid) ? BigInt(object.iid.toString()) : BigInt(0),
      title: (0, _helpers.isSet)(object.title) ? String(object.title) : "",
      state: (0, _helpers.isSet)(object.state) ? issue_StateFromJSON(object.state) : -1,
      description: (0, _helpers.isSet)(object.description) ? String(object.description) : "",
      commentsCount: (0, _helpers.isSet)(object.commentsCount) ? BigInt(object.commentsCount.toString()) : BigInt(0),
      pullRequests: Array.isArray(object === null || object === void 0 ? void 0 : object.pullRequests) ? object.pullRequests.map(function (e) {
        return _repository.PullRequestIid.fromJSON(e);
      }) : [],
      repositoryId: (0, _helpers.isSet)(object.repositoryId) ? BigInt(object.repositoryId.toString()) : BigInt(0),
      labels: Array.isArray(object === null || object === void 0 ? void 0 : object.labels) ? object.labels.map(function (e) {
        return BigInt(e.toString());
      }) : [],
      weight: (0, _helpers.isSet)(object.weight) ? BigInt(object.weight.toString()) : BigInt(0),
      assignees: Array.isArray(object === null || object === void 0 ? void 0 : object.assignees) ? object.assignees.map(function (e) {
        return String(e);
      }) : [],
      bounties: Array.isArray(object === null || object === void 0 ? void 0 : object.bounties) ? object.bounties.map(function (e) {
        return BigInt(e.toString());
      }) : [],
      createdAt: (0, _helpers.isSet)(object.createdAt) ? BigInt(object.createdAt.toString()) : BigInt(0),
      updatedAt: (0, _helpers.isSet)(object.updatedAt) ? BigInt(object.updatedAt.toString()) : BigInt(0),
      closedAt: (0, _helpers.isSet)(object.closedAt) ? BigInt(object.closedAt.toString()) : BigInt(0),
      closedBy: (0, _helpers.isSet)(object.closedBy) ? String(object.closedBy) : ""
    };
  },
  fromPartial: function fromPartial(object) {
    var _object$creator, _object$title, _object$state, _object$description, _object$pullRequests, _object$labels, _object$assignees, _object$bounties, _object$closedBy;
    var message = createBaseIssue();
    message.creator = (_object$creator = object.creator) !== null && _object$creator !== void 0 ? _object$creator : "";
    message.id = object.id !== undefined && object.id !== null ? BigInt(object.id.toString()) : BigInt(0);
    message.iid = object.iid !== undefined && object.iid !== null ? BigInt(object.iid.toString()) : BigInt(0);
    message.title = (_object$title = object.title) !== null && _object$title !== void 0 ? _object$title : "";
    message.state = (_object$state = object.state) !== null && _object$state !== void 0 ? _object$state : 0;
    message.description = (_object$description = object.description) !== null && _object$description !== void 0 ? _object$description : "";
    message.commentsCount = object.commentsCount !== undefined && object.commentsCount !== null ? BigInt(object.commentsCount.toString()) : BigInt(0);
    message.pullRequests = ((_object$pullRequests = object.pullRequests) === null || _object$pullRequests === void 0 ? void 0 : _object$pullRequests.map(function (e) {
      return _repository.PullRequestIid.fromPartial(e);
    })) || [];
    message.repositoryId = object.repositoryId !== undefined && object.repositoryId !== null ? BigInt(object.repositoryId.toString()) : BigInt(0);
    message.labels = ((_object$labels = object.labels) === null || _object$labels === void 0 ? void 0 : _object$labels.map(function (e) {
      return BigInt(e.toString());
    })) || [];
    message.weight = object.weight !== undefined && object.weight !== null ? BigInt(object.weight.toString()) : BigInt(0);
    message.assignees = ((_object$assignees = object.assignees) === null || _object$assignees === void 0 ? void 0 : _object$assignees.map(function (e) {
      return e;
    })) || [];
    message.bounties = ((_object$bounties = object.bounties) === null || _object$bounties === void 0 ? void 0 : _object$bounties.map(function (e) {
      return BigInt(e.toString());
    })) || [];
    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.closedAt = object.closedAt !== undefined && object.closedAt !== null ? BigInt(object.closedAt.toString()) : BigInt(0);
    message.closedBy = (_object$closedBy = object.closedBy) !== null && _object$closedBy !== void 0 ? _object$closedBy : "";
    return message;
  },
  fromAmino: function fromAmino(object) {
    var _object$pullRequests2, _object$labels2, _object$assignees2, _object$bounties2;
    var message = createBaseIssue();
    if (object.creator !== undefined && object.creator !== null) {
      message.creator = object.creator;
    }
    if (object.id !== undefined && object.id !== null) {
      message.id = BigInt(object.id);
    }
    if (object.iid !== undefined && object.iid !== null) {
      message.iid = BigInt(object.iid);
    }
    if (object.title !== undefined && object.title !== null) {
      message.title = object.title;
    }
    if (object.state !== undefined && object.state !== null) {
      message.state = object.state;
    }
    if (object.description !== undefined && object.description !== null) {
      message.description = object.description;
    }
    if (object.commentsCount !== undefined && object.commentsCount !== null) {
      message.commentsCount = BigInt(object.commentsCount);
    }
    message.pullRequests = ((_object$pullRequests2 = object.pullRequests) === null || _object$pullRequests2 === void 0 ? void 0 : _object$pullRequests2.map(function (e) {
      return _repository.PullRequestIid.fromAmino(e);
    })) || [];
    if (object.repositoryId !== undefined && object.repositoryId !== null) {
      message.repositoryId = BigInt(object.repositoryId);
    }
    message.labels = ((_object$labels2 = object.labels) === null || _object$labels2 === void 0 ? void 0 : _object$labels2.map(function (e) {
      return BigInt(e);
    })) || [];
    if (object.weight !== undefined && object.weight !== null) {
      message.weight = BigInt(object.weight);
    }
    message.assignees = ((_object$assignees2 = object.assignees) === null || _object$assignees2 === void 0 ? void 0 : _object$assignees2.map(function (e) {
      return e;
    })) || [];
    message.bounties = ((_object$bounties2 = object.bounties) === null || _object$bounties2 === void 0 ? void 0 : _object$bounties2.map(function (e) {
      return BigInt(e);
    })) || [];
    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.closedAt !== undefined && object.closedAt !== null) {
      message.closedAt = BigInt(object.closedAt);
    }
    if (object.closedBy !== undefined && object.closedBy !== null) {
      message.closedBy = object.closedBy;
    }
    return message;
  },
  toAmino: function toAmino(message) {
    var obj = {};
    obj.creator = message.creator === "" ? undefined : message.creator;
    obj.id = message.id !== BigInt(0) ? message.id.toString() : undefined;
    obj.iid = message.iid !== BigInt(0) ? message.iid.toString() : undefined;
    obj.title = message.title === "" ? undefined : message.title;
    obj.state = message.state === 0 ? undefined : message.state;
    obj.description = message.description === "" ? undefined : message.description;
    obj.commentsCount = message.commentsCount !== BigInt(0) ? message.commentsCount.toString() : undefined;
    if (message.pullRequests) {
      obj.pullRequests = message.pullRequests.map(function (e) {
        return e ? _repository.PullRequestIid.toAmino(e) : undefined;
      });
    } else {
      obj.pullRequests = message.pullRequests;
    }
    obj.repositoryId = message.repositoryId !== BigInt(0) ? message.repositoryId.toString() : undefined;
    if (message.labels) {
      obj.labels = message.labels.map(function (e) {
        return e.toString();
      });
    } else {
      obj.labels = message.labels;
    }
    obj.weight = message.weight !== BigInt(0) ? message.weight.toString() : undefined;
    if (message.assignees) {
      obj.assignees = message.assignees.map(function (e) {
        return e;
      });
    } else {
      obj.assignees = message.assignees;
    }
    if (message.bounties) {
      obj.bounties = message.bounties.map(function (e) {
        return e.toString();
      });
    } else {
      obj.bounties = message.bounties;
    }
    obj.createdAt = message.createdAt !== BigInt(0) ? message.createdAt.toString() : undefined;
    obj.updatedAt = message.updatedAt !== BigInt(0) ? message.updatedAt.toString() : undefined;
    obj.closedAt = message.closedAt !== BigInt(0) ? message.closedAt.toString() : undefined;
    obj.closedBy = message.closedBy === "" ? undefined : message.closedBy;
    return obj;
  },
  fromAminoMsg: function fromAminoMsg(object) {
    return Issue.fromAmino(object.value);
  },
  fromProtoMsg: function fromProtoMsg(message) {
    return Issue.decode(message.value);
  },
  toProto: function toProto(message) {
    return Issue.encode(message).finish();
  },
  toProtoMsg: function toProtoMsg(message) {
    return {
      typeUrl: "/gitopia.gitopia.gitopia.Issue",
      value: Issue.encode(message).finish()
    };
  }
};