"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.QueryRequest=void 0;var Regex_1=require("../mongo-builder/Regex");var AbstractCommand_1=require("./AbstractCommand");var error_1=require("../common/error");var util_1=require("./util");var QueryRequest=function(){function a(i,r,t){if(r===void 0){r=""}if(t===void 0){t=""}this.query=i;this.prefix=r;this.keyName=t}a.prototype.stringify=function(){var i=this;var r=AbstractCommand_1.CommandChain.unchain(this.query);if(r instanceof AbstractCommand_1.LogicQueryCommand){return r.stringifyWithKey(this.keyName)}if(r instanceof AbstractCommand_1.QueryCommand){return r.stringify()}if(r instanceof Regex_1.Regex){return r.stringify()}if(r instanceof RegExp){return r}if(r instanceof Date){return r}if(Array.isArray(r)){return r.map(function(n,u){return new a(n,"".concat(i.prefix,".$.").concat(u)).stringify()})}var t=typeof r;if(t!=="object"){return this.stringifyBuiltInValue(r,t)}if(r===null){return r}return this.stringifyObject(r)};a.prototype.stringifyWithKey=function(){var i,r,t,n,u,s,o;var f=this;var e=AbstractCommand_1.CommandChain.unchain(this.query);if(e instanceof AbstractCommand_1.LogicQueryCommand){return e.stringifyWithKey(this.keyName)}if(e instanceof AbstractCommand_1.QueryCommand){if(e instanceof AbstractCommand_1.EvaluationQueryCommand){return e.stringify()}return i={},i[this.keyName]=e.stringify(),i}if(e instanceof Regex_1.Regex){return r={},r[this.keyName]=e.stringify(),r}if(e instanceof RegExp){return t={},t[this.keyName]=e,t}if(e instanceof Date){return n={},n[this.keyName]=e,n}if(Array.isArray(e)){var y=e.map(function(m,h){return new a(m,"".concat(f.prefix,".$.").concat(h)).stringify()});return u={},u[this.keyName]=y,u}var c=typeof e;if(c!=="object"){return s={},s[this.keyName]=this.stringifyBuiltInValue(e,c),s}if(e===null){return o={},o[this.keyName]=e,o}return this.stringifyObject(e)};a.prototype.toJSON=function(){var i=this.stringify();if(i===void 0){throw error_1.DbBuildError.invalidParam(this.prefix,"\u4E0D\u652F\u6301 undefined")}return i};a.prototype.stringifyBuiltInValue=function(i,r){switch(r){case"number":return i;case"boolean":return i;case"string":return i;case"bigint":return i;case"function":throw error_1.DbBuildError.invalidParam(this.prefix,"\u4E0D\u652F\u6301\u51FD\u6570");case"symbol":throw error_1.DbBuildError.invalidParam(this.prefix,"\u4E0D\u652F\u6301 symbol");case"undefined":return void 0;default:return i}};a.prototype.stringifyObject=function(i){var r;var t={};for(var n in i){var u=this.prefix?"".concat(this.prefix,".").concat(n):n;var s=AbstractCommand_1.CommandChain.unchain(i[n]);if(s instanceof AbstractCommand_1.LogicQueryCommand){var o=s.stringifyWithKey(u);util_1.RequestUtil.mergeTo(t,o)}else{var f=new a(s,u,n).stringify();if(f!==void 0){util_1.RequestUtil.mergeTo(t,(r={},r[n]=f,r))}}}return t};return a}();exports.QueryRequest=QueryRequest;