"use strict";var __assign=this&&this.__assign||function(){__assign=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++){e=arguments[r];for(var o in e)if(Object.prototype.hasOwnProperty.call(e,o))t[o]=e[o]}return t};return __assign.apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:true});exports.CollectionBuilder=void 0;var constant_1=require("../common/constant");var error_1=require("../common/error");var util_1=require("../common/util");var Aggregate_1=require("./Aggregate");var Document_1=require("./Document");var Query_1=require("./Query");var GeoRequest_1=require("../command/GeoRequest");var CollectionBuilder=function(){function t(e,r){this.collectionName=e;this.options=__assign({maxAddCount:200},r)}t.prototype.add=function(e){if(!(e===null||e===void 0?void 0:e.data)){throw error_1.DbBuildError.invalidParam("data","\u4E0D\u80FD\u4E3A\u7A7A")}if(Array.isArray(e.data)){return this.batchAdd(e)}var r=new GeoRequest_1.GeoRequest(e.data).stringify();return util_1.ActionBuilder.buildDocumentAction(constant_1.DocumentAction.create,this.collectionName,r)};t.prototype.batchAdd=function(e){if(e.data.length<=0){throw error_1.DbBuildError.invalidParam("data","\u4E0D\u80FD\u4E3A\u7A7A\u6570\u7EC4")}if(e.data.length>this.options.maxAddCount){throw error_1.DbBuildError.invalidParam("data","\u6700\u5927\u957F\u5EA6 ".concat(this.options.maxAddCount))}var r={$create:new GeoRequest_1.GeoRequest(e.data).stringify()};if(typeof e.ordered==="boolean"){r.$ordered=e.ordered}return util_1.ActionBuilder.buildDocumentAction(constant_1.DocumentAction.batchCreate,this.collectionName,r)};t.prototype.doc=function(e){return new Document_1.DocumentBuilder(this.collectionName,e)};t.prototype.limit=function(e){return new Query_1.QueryBuilder(this.collectionName).limit(e)};t.prototype.skip=function(e){return new Query_1.QueryBuilder(this.collectionName).skip(e)};t.prototype.where=function(e){return new Query_1.QueryBuilder(this.collectionName).where(e)};t.prototype.projection=function(e){return new Query_1.QueryBuilder(this.collectionName).projection(e)};t.prototype.orderBy=function(e,r){return new Query_1.QueryBuilder(this.collectionName).orderBy(e,r)};t.prototype.aggregate=function(){return new Aggregate_1.AggregateBuilder(this.collectionName)};t.prototype.get=function(){return new Query_1.QueryBuilder(this.collectionName).get()};t.prototype.count=function(){return new Query_1.QueryBuilder(this.collectionName).count()};return t}();exports.CollectionBuilder=CollectionBuilder;