/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import e from"../../../core/Error.js";import{convertRecursiveBindParam as n}from"./queryToWasmEncodedFactories.js";import{inputQuantizationParametersToWasmFormat as t}from"./updateToWasmEncodedFactories.js";function i(e,n){const t=new n.UnregisterReplicaRequestEncoder;if(t.deleteLater(),e.unregisterAll)t.set_unregister_all();else{const{replicaIds:n=[]}=e;n.forEach(e=>t.add_replica_id(e))}return t}function r(e,n){const t=new n.CreateReplicaRequestEncoder;return t.deleteLater(),e.requestedReplicaId&&(t.replica_id=e.requestedReplicaId),e.requestedReplicaName&&(t.requested_replica_name=e.requestedReplicaName),t.sync_direction=_(e.syncDirection,n),t.sync_data_format=y(e.syncDataFormat,n),t.async=!1,"reference"===e.type&&(t.reference_replica=c(e.referenceReplica,n)),"filter"===e.type&&(t.replica_filters=o(e.replicaFilters,n)),t}function c(e,n){const t=new n.ReferenceReplica;return t.deleteLater(),t.replica_id=e.replicaId,t}function o(e,n){const i=e.inputQuantizationParameters?t(e.inputQuantizationParameters):n.InputQuantizationUtil.WGS84_lossless(),r=a(e.staticDefinition,n),c=new n.ReplicaFilters(r);return c.deleteLater(),c.input_quantization_parameters=i,e.inputSpatialReference&&(c.input_spatial_reference=e.inputSpatialReference),c}function a(n,t){const i=new t.StaticDefinition;i.deleteLater();const r=n.entityTypeReplicaDefinitions??[],c=n.relationshipTypeReplicaDefinitions??[];if(r.length<1&&c.length<1)throw new e("knowledge-graph:replica-invalid-static-definition","A Filter Replica static definition must include at least one entity type or relationship type replica definition");for(const e of r)i.add_entity_type_replica_definition(p(e,t));for(const e of c)i.add_relationship_type_replica_definition(s(e,t));return i}function p(e,n){const t=new n.EntityTypeReplicaDefinition;return t.deleteLater(),l(e,n,t),e.documentOptions&&(t.document_options=u(e.documentOptions,n)),t}function s(e,n){const t=new n.RelationshipTypeReplicaDefinition;return t.deleteLater(),l(e,n,t),t}function l(e,t,i){if(i.type_name=e.typeName,i.open_cypher_where_clause=e.openCypherWhereClause??"",e.provenanceOptions&&(i.provenance_options=f(e.provenanceOptions,t)),e.parameters)for(const[r,c]of Object.entries(e.parameters))void 0!==c&&i.add_parameter(r,n(c,t));return i}function u(e,n){const t=e.includeConnectedDocuments?d(e,n):void 0,i=new n.DocumentOptions(t);return i.deleteLater(),i}function d(e,n){const t=f(e.includeDocumentProvenance?{includeProvenance:!0,includeSourceDocuments:e.includeDocumentSourceDocuments}:{includeProvenance:!1},n),i=new n.IncludeConnectedDocuments(t);return i.deleteLater(),i}function f(e,n){const t=m(e,n),i=new n.ProvenanceOptions(t);return i.deleteLater(),i}function m(e,n){const t=new n.IncludeProvenance("includeSourceDocuments"in e&&e.includeSourceDocuments);return t.deleteLater(),t}function _(n,t){const i=t.SyncDirection,r=n.toUpperCase(),c=i?.[r];if(!c)throw new e("knowledge-graph:replica-invalid-sync-direction",`Unsupported replica sync direction: ${n}`);return c}function y(n,t){const i=t.SyncDataFormat,r=n.toUpperCase(),c=i?.[r];if(!c)throw new e("knowledge-graph:replica-invalid-sync-data-format",`Unsupported replica sync data format: ${n}`);return c}export{u as documentOptionsToWasm,p as entityTypeReplicaDefinitionToWasm,d as includeConnectedDocumentsToWasm,m as includeProvenanceToWasm,l as namedTypeReplicaDefinitionToWasm,f as provenanceOptionsToWasm,c as referenceReplicaToWasm,s as relationshipTypeReplicaDefinitionToWasm,o as replicaFiltersToWasm,i as replicaIdsToWasmUnregisterReplicaRequestEncoder,r as replicaToWasmCreateReplicaRequestEncoder,a as staticDefinitionToWasm,y as toWasmSyncDataFormatEnum,_ as toWasmSyncDirectionEnum};
