"use strict";module.exports=ReflectionObject,ReflectionObject.className="ReflectionObject";let OneOf=require("./oneof");var Root,util=require("./util"),editions2023Defaults={enum_type:"OPEN",field_presence:"EXPLICIT",json_format:"ALLOW",message_encoding:"LENGTH_PREFIXED",repeated_field_encoding:"PACKED",utf8_validation:"VERIFY"},proto2Defaults={enum_type:"CLOSED",field_presence:"EXPLICIT",json_format:"LEGACY_BEST_EFFORT",message_encoding:"LENGTH_PREFIXED",repeated_field_encoding:"EXPANDED",utf8_validation:"NONE"},proto3Defaults={enum_type:"OPEN",field_presence:"IMPLICIT",json_format:"ALLOW",message_encoding:"LENGTH_PREFIXED",repeated_field_encoding:"PACKED",utf8_validation:"VERIFY"};function ReflectionObject(t,e){if(!util.isString(t))throw TypeError("name must be a string");if(e&&!util.isObject(e))throw TypeError("options must be an object");this.options=e,this.parsedOptions=null,this.name=t,this._edition=null,this._defaultEdition="proto2",this._features={},this._featuresResolved=!1,this.parent=null,this.resolved=!1,this.comment=null,this.filename=null}Object.defineProperties(ReflectionObject.prototype,{root:{get:function(){for(var t=this;null!==t.parent;)t=t.parent;return t}},fullName:{get:function(){for(var t=[this.name],e=this.parent;e;)t.unshift(e.name),e=e.parent;return t.join(".")}}}),ReflectionObject.prototype.toJSON=function(){throw Error()},ReflectionObject.prototype.onAdd=function(t){this.parent&&this.parent!==t&&this.parent.remove(this),this.parent=t,this.resolved=!1;var e=t.root;e instanceof Root&&e._handleAdd(this)},ReflectionObject.prototype.onRemove=function(t){var e=t.root;e instanceof Root&&e._handleRemove(this),this.parent=null,this.resolved=!1},ReflectionObject.prototype.resolve=function(){return this.resolved||this.root instanceof Root&&(this.resolved=!0),this},ReflectionObject.prototype._resolveFeaturesRecursive=function(t){return this._resolveFeatures(this._edition||t)},ReflectionObject.prototype._resolveFeatures=function(t){if(!this._featuresResolved){var e={};if(!t)throw Error("Unknown edition for "+this.fullName);var i=Object.assign(this.options?Object.assign({},this.options.features):{},this._inferLegacyProtoFeatures(t));if(this._edition){if("proto2"===t)e=Object.assign({},proto2Defaults);else if("proto3"===t)e=Object.assign({},proto3Defaults);else if("2023"===t)e=Object.assign({},editions2023Defaults);else throw Error("Unknown edition: "+t);this._features=Object.assign(e,i||{}),this._featuresResolved=!0;return}if(this.partOf instanceof OneOf){var o=Object.assign({},this.partOf._features);this._features=Object.assign(o,i||{})}else if(this.declaringField);else if(this.parent){var s=Object.assign({},this.parent._features);this._features=Object.assign(s,i||{})}else throw Error("Unable to find a parent for "+this.fullName);this.extensionField&&(this.extensionField._features=this._features),this._featuresResolved=!0}},ReflectionObject.prototype._inferLegacyProtoFeatures=function(){return{}},ReflectionObject.prototype.getOption=function(t){if(this.options)return this.options[t]},ReflectionObject.prototype.setOption=function(t,e,i){return this.options||(this.options={}),/^features\./.test(t)?util.setProperty(this.options,t,e,i):i&&void 0!==this.options[t]||(this.getOption(t)!==e&&(this.resolved=!1),this.options[t]=e),this},ReflectionObject.prototype.setParsedOption=function(t,e,i){this.parsedOptions||(this.parsedOptions=[]);var o=this.parsedOptions;if(i){var s=o.find(function(e){return Object.prototype.hasOwnProperty.call(e,t)});if(s){var n=s[t];util.setProperty(n,i,e)}else(s={})[t]=util.setProperty({},i,e),o.push(s)}else{var r={};r[t]=e,o.push(r)}return this},ReflectionObject.prototype.setOptions=function(t,e){if(t)for(var i=Object.keys(t),o=0;o<i.length;++o)this.setOption(i[o],t[i[o]],e);return this},ReflectionObject.prototype.toString=function(){var t=this.constructor.className,e=this.fullName;return e.length?t+" "+e:t},ReflectionObject.prototype._editionToJSON=function(){if(this._edition&&"proto3"!==this._edition)return this._edition},ReflectionObject._configure=function(t){Root=t};