import{Regex as g}from"../mongo-builder/Regex";import{CommandChain as y,EvaluationQueryCommand as x,LogicQueryCommand as c,QueryCommand as p}from"./AbstractCommand";import{DbBuildError as h}from"../common/error";import{RequestUtil as d}from"./util";var _=function(){function f(r,i,n){if(i===void 0){i=""}if(n===void 0){n=""}this.query=r;this.prefix=i;this.keyName=n}f.prototype.stringify=function(){var r=this;var i=y.unchain(this.query);if(i instanceof c){return i.stringifyWithKey(this.keyName)}if(i instanceof p){return i.stringify()}if(i instanceof g){return i.stringify()}if(i instanceof RegExp){return i}if(i instanceof Date){return i}if(Array.isArray(i)){return i.map(function(e,s){return new f(e,"".concat(r.prefix,".$.").concat(s)).stringify()})}var n=typeof i;if(n!=="object"){return this.stringifyBuiltInValue(i,n)}if(i===null){return i}return this.stringifyObject(i)};f.prototype.stringifyWithKey=function(){var r,i,n,e,s,a,o;var u=this;var t=y.unchain(this.query);if(t instanceof c){return t.stringifyWithKey(this.keyName)}if(t instanceof p){if(t instanceof x){return t.stringify()}return r={},r[this.keyName]=t.stringify(),r}if(t instanceof g){return i={},i[this.keyName]=t.stringify(),i}if(t instanceof RegExp){return n={},n[this.keyName]=t,n}if(t instanceof Date){return e={},e[this.keyName]=t,e}if(Array.isArray(t)){var v=t.map(function(l,b){return new f(l,"".concat(u.prefix,".$.").concat(b)).stringify()});return s={},s[this.keyName]=v,s}var m=typeof t;if(m!=="object"){return a={},a[this.keyName]=this.stringifyBuiltInValue(t,m),a}if(t===null){return o={},o[this.keyName]=t,o}return this.stringifyObject(t)};f.prototype.toJSON=function(){var r=this.stringify();if(r===void 0){throw h.invalidParam(this.prefix,"\u4E0D\u652F\u6301 undefined")}return r};f.prototype.stringifyBuiltInValue=function(r,i){switch(i){case"number":return r;case"boolean":return r;case"string":return r;case"bigint":return r;case"function":throw h.invalidParam(this.prefix,"\u4E0D\u652F\u6301\u51FD\u6570");case"symbol":throw h.invalidParam(this.prefix,"\u4E0D\u652F\u6301 symbol");case"undefined":return void 0;default:return r}};f.prototype.stringifyObject=function(r){var i;var n={};for(var e in r){var s=this.prefix?"".concat(this.prefix,".").concat(e):e;var a=y.unchain(r[e]);if(a instanceof c){var o=a.stringifyWithKey(s);d.mergeTo(n,o)}else{var u=new f(a,s,e).stringify();if(u!==void 0){d.mergeTo(n,(i={},i[e]=u,i))}}}return n};return f}();export{_ as QueryRequest};