"use strict";

var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.IidDocument = void 0;
var _types = require("./types");
var _m0 = _interopRequireWildcard(require("protobufjs/minimal"));
var _helpers = require("../../../helpers");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } //@ts-nocheck
function createBaseIidDocument() {
  return {
    context: [],
    id: "",
    controller: [],
    verificationMethod: [],
    service: [],
    authentication: [],
    assertionMethod: [],
    keyAgreement: [],
    capabilityInvocation: [],
    capabilityDelegation: [],
    linkedResource: [],
    linkedClaim: [],
    accordedRight: [],
    linkedEntity: [],
    alsoKnownAs: "",
    metadata: undefined
  };
}
var IidDocument = exports.IidDocument = {
  encode: function encode(message) {
    var writer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _m0.Writer.create();
    var _iterator = _createForOfIteratorHelper(message.context),
      _step;
    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var v = _step.value;
        _types.Context.encode(v, writer.uint32(10).fork()).ldelim();
      }
    } catch (err) {
      _iterator.e(err);
    } finally {
      _iterator.f();
    }
    if (message.id !== "") {
      writer.uint32(18).string(message.id);
    }
    var _iterator2 = _createForOfIteratorHelper(message.controller),
      _step2;
    try {
      for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
        var _v = _step2.value;
        writer.uint32(26).string(_v);
      }
    } catch (err) {
      _iterator2.e(err);
    } finally {
      _iterator2.f();
    }
    var _iterator3 = _createForOfIteratorHelper(message.verificationMethod),
      _step3;
    try {
      for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
        var _v2 = _step3.value;
        _types.VerificationMethod.encode(_v2, writer.uint32(34).fork()).ldelim();
      }
    } catch (err) {
      _iterator3.e(err);
    } finally {
      _iterator3.f();
    }
    var _iterator4 = _createForOfIteratorHelper(message.service),
      _step4;
    try {
      for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
        var _v3 = _step4.value;
        _types.Service.encode(_v3, writer.uint32(42).fork()).ldelim();
      }
    } catch (err) {
      _iterator4.e(err);
    } finally {
      _iterator4.f();
    }
    var _iterator5 = _createForOfIteratorHelper(message.authentication),
      _step5;
    try {
      for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
        var _v4 = _step5.value;
        writer.uint32(50).string(_v4);
      }
    } catch (err) {
      _iterator5.e(err);
    } finally {
      _iterator5.f();
    }
    var _iterator6 = _createForOfIteratorHelper(message.assertionMethod),
      _step6;
    try {
      for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
        var _v5 = _step6.value;
        writer.uint32(58).string(_v5);
      }
    } catch (err) {
      _iterator6.e(err);
    } finally {
      _iterator6.f();
    }
    var _iterator7 = _createForOfIteratorHelper(message.keyAgreement),
      _step7;
    try {
      for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
        var _v6 = _step7.value;
        writer.uint32(66).string(_v6);
      }
    } catch (err) {
      _iterator7.e(err);
    } finally {
      _iterator7.f();
    }
    var _iterator8 = _createForOfIteratorHelper(message.capabilityInvocation),
      _step8;
    try {
      for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
        var _v7 = _step8.value;
        writer.uint32(74).string(_v7);
      }
    } catch (err) {
      _iterator8.e(err);
    } finally {
      _iterator8.f();
    }
    var _iterator9 = _createForOfIteratorHelper(message.capabilityDelegation),
      _step9;
    try {
      for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
        var _v8 = _step9.value;
        writer.uint32(82).string(_v8);
      }
    } catch (err) {
      _iterator9.e(err);
    } finally {
      _iterator9.f();
    }
    var _iterator0 = _createForOfIteratorHelper(message.linkedResource),
      _step0;
    try {
      for (_iterator0.s(); !(_step0 = _iterator0.n()).done;) {
        var _v9 = _step0.value;
        _types.LinkedResource.encode(_v9, writer.uint32(90).fork()).ldelim();
      }
    } catch (err) {
      _iterator0.e(err);
    } finally {
      _iterator0.f();
    }
    var _iterator1 = _createForOfIteratorHelper(message.linkedClaim),
      _step1;
    try {
      for (_iterator1.s(); !(_step1 = _iterator1.n()).done;) {
        var _v0 = _step1.value;
        _types.LinkedClaim.encode(_v0, writer.uint32(98).fork()).ldelim();
      }
    } catch (err) {
      _iterator1.e(err);
    } finally {
      _iterator1.f();
    }
    var _iterator10 = _createForOfIteratorHelper(message.accordedRight),
      _step10;
    try {
      for (_iterator10.s(); !(_step10 = _iterator10.n()).done;) {
        var _v1 = _step10.value;
        _types.AccordedRight.encode(_v1, writer.uint32(106).fork()).ldelim();
      }
    } catch (err) {
      _iterator10.e(err);
    } finally {
      _iterator10.f();
    }
    var _iterator11 = _createForOfIteratorHelper(message.linkedEntity),
      _step11;
    try {
      for (_iterator11.s(); !(_step11 = _iterator11.n()).done;) {
        var _v10 = _step11.value;
        _types.LinkedEntity.encode(_v10, writer.uint32(114).fork()).ldelim();
      }
    } catch (err) {
      _iterator11.e(err);
    } finally {
      _iterator11.f();
    }
    if (message.alsoKnownAs !== "") {
      writer.uint32(122).string(message.alsoKnownAs);
    }
    if (message.metadata !== undefined) {
      _types.IidMetadata.encode(message.metadata, writer.uint32(130).fork()).ldelim();
    }
    return writer;
  },
  decode: function decode(input, length) {
    var reader = input instanceof _m0.Reader ? input : new _m0.Reader(input);
    var end = length === undefined ? reader.len : reader.pos + length;
    var message = createBaseIidDocument();
    while (reader.pos < end) {
      var tag = reader.uint32();
      switch (tag >>> 3) {
        case 1:
          message.context.push(_types.Context.decode(reader, reader.uint32()));
          break;
        case 2:
          message.id = reader.string();
          break;
        case 3:
          message.controller.push(reader.string());
          break;
        case 4:
          message.verificationMethod.push(_types.VerificationMethod.decode(reader, reader.uint32()));
          break;
        case 5:
          message.service.push(_types.Service.decode(reader, reader.uint32()));
          break;
        case 6:
          message.authentication.push(reader.string());
          break;
        case 7:
          message.assertionMethod.push(reader.string());
          break;
        case 8:
          message.keyAgreement.push(reader.string());
          break;
        case 9:
          message.capabilityInvocation.push(reader.string());
          break;
        case 10:
          message.capabilityDelegation.push(reader.string());
          break;
        case 11:
          message.linkedResource.push(_types.LinkedResource.decode(reader, reader.uint32()));
          break;
        case 12:
          message.linkedClaim.push(_types.LinkedClaim.decode(reader, reader.uint32()));
          break;
        case 13:
          message.accordedRight.push(_types.AccordedRight.decode(reader, reader.uint32()));
          break;
        case 14:
          message.linkedEntity.push(_types.LinkedEntity.decode(reader, reader.uint32()));
          break;
        case 15:
          message.alsoKnownAs = reader.string();
          break;
        case 16:
          message.metadata = _types.IidMetadata.decode(reader, reader.uint32());
          break;
        default:
          reader.skipType(tag & 7);
          break;
      }
    }
    return message;
  },
  fromJSON: function fromJSON(object) {
    return {
      context: Array.isArray(object === null || object === void 0 ? void 0 : object.context) ? object.context.map(function (e) {
        return _types.Context.fromJSON(e);
      }) : [],
      id: (0, _helpers.isSet)(object.id) ? String(object.id) : "",
      controller: Array.isArray(object === null || object === void 0 ? void 0 : object.controller) ? object.controller.map(function (e) {
        return String(e);
      }) : [],
      verificationMethod: Array.isArray(object === null || object === void 0 ? void 0 : object.verificationMethod) ? object.verificationMethod.map(function (e) {
        return _types.VerificationMethod.fromJSON(e);
      }) : [],
      service: Array.isArray(object === null || object === void 0 ? void 0 : object.service) ? object.service.map(function (e) {
        return _types.Service.fromJSON(e);
      }) : [],
      authentication: Array.isArray(object === null || object === void 0 ? void 0 : object.authentication) ? object.authentication.map(function (e) {
        return String(e);
      }) : [],
      assertionMethod: Array.isArray(object === null || object === void 0 ? void 0 : object.assertionMethod) ? object.assertionMethod.map(function (e) {
        return String(e);
      }) : [],
      keyAgreement: Array.isArray(object === null || object === void 0 ? void 0 : object.keyAgreement) ? object.keyAgreement.map(function (e) {
        return String(e);
      }) : [],
      capabilityInvocation: Array.isArray(object === null || object === void 0 ? void 0 : object.capabilityInvocation) ? object.capabilityInvocation.map(function (e) {
        return String(e);
      }) : [],
      capabilityDelegation: Array.isArray(object === null || object === void 0 ? void 0 : object.capabilityDelegation) ? object.capabilityDelegation.map(function (e) {
        return String(e);
      }) : [],
      linkedResource: Array.isArray(object === null || object === void 0 ? void 0 : object.linkedResource) ? object.linkedResource.map(function (e) {
        return _types.LinkedResource.fromJSON(e);
      }) : [],
      linkedClaim: Array.isArray(object === null || object === void 0 ? void 0 : object.linkedClaim) ? object.linkedClaim.map(function (e) {
        return _types.LinkedClaim.fromJSON(e);
      }) : [],
      accordedRight: Array.isArray(object === null || object === void 0 ? void 0 : object.accordedRight) ? object.accordedRight.map(function (e) {
        return _types.AccordedRight.fromJSON(e);
      }) : [],
      linkedEntity: Array.isArray(object === null || object === void 0 ? void 0 : object.linkedEntity) ? object.linkedEntity.map(function (e) {
        return _types.LinkedEntity.fromJSON(e);
      }) : [],
      alsoKnownAs: (0, _helpers.isSet)(object.alsoKnownAs) ? String(object.alsoKnownAs) : "",
      metadata: (0, _helpers.isSet)(object.metadata) ? _types.IidMetadata.fromJSON(object.metadata) : undefined
    };
  },
  toJSON: function toJSON(message) {
    var obj = {};
    if (message.context) {
      obj.context = message.context.map(function (e) {
        return e ? _types.Context.toJSON(e) : undefined;
      });
    } else {
      obj.context = [];
    }
    message.id !== undefined && (obj.id = message.id);
    if (message.controller) {
      obj.controller = message.controller.map(function (e) {
        return e;
      });
    } else {
      obj.controller = [];
    }
    if (message.verificationMethod) {
      obj.verificationMethod = message.verificationMethod.map(function (e) {
        return e ? _types.VerificationMethod.toJSON(e) : undefined;
      });
    } else {
      obj.verificationMethod = [];
    }
    if (message.service) {
      obj.service = message.service.map(function (e) {
        return e ? _types.Service.toJSON(e) : undefined;
      });
    } else {
      obj.service = [];
    }
    if (message.authentication) {
      obj.authentication = message.authentication.map(function (e) {
        return e;
      });
    } else {
      obj.authentication = [];
    }
    if (message.assertionMethod) {
      obj.assertionMethod = message.assertionMethod.map(function (e) {
        return e;
      });
    } else {
      obj.assertionMethod = [];
    }
    if (message.keyAgreement) {
      obj.keyAgreement = message.keyAgreement.map(function (e) {
        return e;
      });
    } else {
      obj.keyAgreement = [];
    }
    if (message.capabilityInvocation) {
      obj.capabilityInvocation = message.capabilityInvocation.map(function (e) {
        return e;
      });
    } else {
      obj.capabilityInvocation = [];
    }
    if (message.capabilityDelegation) {
      obj.capabilityDelegation = message.capabilityDelegation.map(function (e) {
        return e;
      });
    } else {
      obj.capabilityDelegation = [];
    }
    if (message.linkedResource) {
      obj.linkedResource = message.linkedResource.map(function (e) {
        return e ? _types.LinkedResource.toJSON(e) : undefined;
      });
    } else {
      obj.linkedResource = [];
    }
    if (message.linkedClaim) {
      obj.linkedClaim = message.linkedClaim.map(function (e) {
        return e ? _types.LinkedClaim.toJSON(e) : undefined;
      });
    } else {
      obj.linkedClaim = [];
    }
    if (message.accordedRight) {
      obj.accordedRight = message.accordedRight.map(function (e) {
        return e ? _types.AccordedRight.toJSON(e) : undefined;
      });
    } else {
      obj.accordedRight = [];
    }
    if (message.linkedEntity) {
      obj.linkedEntity = message.linkedEntity.map(function (e) {
        return e ? _types.LinkedEntity.toJSON(e) : undefined;
      });
    } else {
      obj.linkedEntity = [];
    }
    message.alsoKnownAs !== undefined && (obj.alsoKnownAs = message.alsoKnownAs);
    message.metadata !== undefined && (obj.metadata = message.metadata ? _types.IidMetadata.toJSON(message.metadata) : undefined);
    return obj;
  },
  fromPartial: function fromPartial(object) {
    var _object$context, _object$id, _object$controller, _object$verificationM, _object$service, _object$authenticatio, _object$assertionMeth, _object$keyAgreement, _object$capabilityInv, _object$capabilityDel, _object$linkedResourc, _object$linkedClaim, _object$accordedRight, _object$linkedEntity, _object$alsoKnownAs;
    var message = createBaseIidDocument();
    message.context = ((_object$context = object.context) === null || _object$context === void 0 ? void 0 : _object$context.map(function (e) {
      return _types.Context.fromPartial(e);
    })) || [];
    message.id = (_object$id = object.id) !== null && _object$id !== void 0 ? _object$id : "";
    message.controller = ((_object$controller = object.controller) === null || _object$controller === void 0 ? void 0 : _object$controller.map(function (e) {
      return e;
    })) || [];
    message.verificationMethod = ((_object$verificationM = object.verificationMethod) === null || _object$verificationM === void 0 ? void 0 : _object$verificationM.map(function (e) {
      return _types.VerificationMethod.fromPartial(e);
    })) || [];
    message.service = ((_object$service = object.service) === null || _object$service === void 0 ? void 0 : _object$service.map(function (e) {
      return _types.Service.fromPartial(e);
    })) || [];
    message.authentication = ((_object$authenticatio = object.authentication) === null || _object$authenticatio === void 0 ? void 0 : _object$authenticatio.map(function (e) {
      return e;
    })) || [];
    message.assertionMethod = ((_object$assertionMeth = object.assertionMethod) === null || _object$assertionMeth === void 0 ? void 0 : _object$assertionMeth.map(function (e) {
      return e;
    })) || [];
    message.keyAgreement = ((_object$keyAgreement = object.keyAgreement) === null || _object$keyAgreement === void 0 ? void 0 : _object$keyAgreement.map(function (e) {
      return e;
    })) || [];
    message.capabilityInvocation = ((_object$capabilityInv = object.capabilityInvocation) === null || _object$capabilityInv === void 0 ? void 0 : _object$capabilityInv.map(function (e) {
      return e;
    })) || [];
    message.capabilityDelegation = ((_object$capabilityDel = object.capabilityDelegation) === null || _object$capabilityDel === void 0 ? void 0 : _object$capabilityDel.map(function (e) {
      return e;
    })) || [];
    message.linkedResource = ((_object$linkedResourc = object.linkedResource) === null || _object$linkedResourc === void 0 ? void 0 : _object$linkedResourc.map(function (e) {
      return _types.LinkedResource.fromPartial(e);
    })) || [];
    message.linkedClaim = ((_object$linkedClaim = object.linkedClaim) === null || _object$linkedClaim === void 0 ? void 0 : _object$linkedClaim.map(function (e) {
      return _types.LinkedClaim.fromPartial(e);
    })) || [];
    message.accordedRight = ((_object$accordedRight = object.accordedRight) === null || _object$accordedRight === void 0 ? void 0 : _object$accordedRight.map(function (e) {
      return _types.AccordedRight.fromPartial(e);
    })) || [];
    message.linkedEntity = ((_object$linkedEntity = object.linkedEntity) === null || _object$linkedEntity === void 0 ? void 0 : _object$linkedEntity.map(function (e) {
      return _types.LinkedEntity.fromPartial(e);
    })) || [];
    message.alsoKnownAs = (_object$alsoKnownAs = object.alsoKnownAs) !== null && _object$alsoKnownAs !== void 0 ? _object$alsoKnownAs : "";
    message.metadata = object.metadata !== undefined && object.metadata !== null ? _types.IidMetadata.fromPartial(object.metadata) : undefined;
    return message;
  }
};