"use strict";module.exports=Enum;var ReflectionObject=require("./object");((Enum.prototype=Object.create(ReflectionObject.prototype)).constructor=Enum).className="Enum";var Namespace=require("./namespace"),util=require("./util");function Enum(e,t,s,i,r,o){if(ReflectionObject.call(this,e,s),t&&"object"!=typeof t)throw TypeError("values must be an object");if(this.valuesById={},this.values=Object.create(this.valuesById),this.comment=i,this.comments=r||{},this.valuesOptions=o,this._valuesFeatures={},this.reserved=void 0,t)for(var n=Object.keys(t),u=0;u<n.length;++u)"number"==typeof t[n[u]]&&(this.valuesById[this.values[n[u]]=t[n[u]]]=n[u])}Enum.prototype._resolveFeatures=function(e){return e=this._edition||e,ReflectionObject.prototype._resolveFeatures.call(this,e),Object.keys(this.values).forEach(e=>{var t=Object.assign({},this._features);this._valuesFeatures[e]=Object.assign(t,this.valuesOptions&&this.valuesOptions[e]&&this.valuesOptions[e].features)}),this},Enum.fromJSON=function(e,t){var s=new Enum(e,t.values,t.options,t.comment,t.comments);return s.reserved=t.reserved,t.edition&&(s._edition=t.edition),s._defaultEdition="proto3",s},Enum.prototype.toJSON=function(e){var t=!!e&&!!e.keepComments;return util.toObject(["edition",this._editionToJSON(),"options",this.options,"valuesOptions",this.valuesOptions,"values",this.values,"reserved",this.reserved&&this.reserved.length?this.reserved:void 0,"comment",t?this.comment:void 0,"comments",t?this.comments:void 0])},Enum.prototype.add=function(e,t,s,i){if(!util.isString(e))throw TypeError("name must be a string");if(!util.isInteger(t))throw TypeError("id must be an integer");if(void 0!==this.values[e])throw Error("duplicate name '"+e+"' in "+this);if(this.isReservedId(t))throw Error("id "+t+" is reserved in "+this);if(this.isReservedName(e))throw Error("name '"+e+"' is reserved in "+this);if(void 0!==this.valuesById[t]){if(!(this.options&&this.options.allow_alias))throw Error("duplicate id "+t+" in "+this);this.values[e]=t}else this.valuesById[this.values[e]=t]=e;return i&&(void 0===this.valuesOptions&&(this.valuesOptions={}),this.valuesOptions[e]=i||null),this.comments[e]=s||null,this},Enum.prototype.remove=function(e){if(!util.isString(e))throw TypeError("name must be a string");var t=this.values[e];if(null==t)throw Error("name '"+e+"' does not exist in "+this);return delete this.valuesById[t],delete this.values[e],delete this.comments[e],this.valuesOptions&&delete this.valuesOptions[e],this},Enum.prototype.isReservedId=function(e){return Namespace.isReservedId(this.reserved,e)},Enum.prototype.isReservedName=function(e){return Namespace.isReservedName(this.reserved,e)};