/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import"../../../../../core/has.js";import{clone as e}from"../../../../../core/lang.js";import{isHostedAgolService as t}from"../../../../../layers/support/arcgisLayerUrl.js";import"../../../../../renderers/SimpleRenderer.js";import"../../../../../symbols/support/defaults.js";import{getSortKey as r}from"../schema/processor/SimpleProcessorSchema.js";import{createFeatureIdInfo as s}from"./featureServiceUtils.js";import{getServiceGeometryType as i}from"./geometryUtils.js";import{ExceedsLimitCache as a}from"../schema/ExceedsLimitCache.js";import{createSnapshotInfo as o,createFeatureSourceSchema as n}from"../schema/SourceSchema.js";import{createStorageSchema as l}from"../schema/processor/StorageSchema.js";import{getDimensionMatcherSchema as p}from"../../support/annodime/dimensionSchema.js";import{dimensionRealFields as c,dimensionVirtualFields as u}from"../../support/annodime/fields.js";import{getReferenceScale as m}from"../../support/annodime/utils.js";class d{constructor(e){this.layer=e,this._cache=new a}getLabelingDeconflictionInfo(){return[]}async createSourceSchema(e,t){const r=this._createServiceInfo(e),s=null!=this.layer.editingInfo?.lastEditDate,i=this.layer.refreshInterval>0,a=!s&&i,l=o("isSourceHosted"in r&&r.isSourceHosted,a,this.layer.capabilities,r.metadata.geometryType,e.extent,this.layer.fullExtent);let p=[];return p=e.availableFields.concat(...c),n(r,l,{definitionExpression:this.layer.definitionExpression,queryScaleRanges:[],displayFilterEnabled:!1,displayFilterInfo:null,customParameters:this.layer.customParameters,gdbVersion:this.layer.gdbVersion,historicMoment:this.layer.historicMoment,timeExtent:this.layer.timeExtent,apiKey:this.layer.apiKey,sourceRefreshVersion:t,availableFields:p,cache:this._cache,postQueryFilter:null,returnM:!1,returnZ:!1})}async createProcessorSchema(e,t,s){const{meshes:i,referenceScale:a}=await this._fetchDimensionDataElementRequest(e,{type:"dimension-data-element-request"}),{objectIdField:o}=this.layer,n=r(null,null,o);return{storage:l(null,t.filters),mesh:{properties:{sortKey:n,timeZone:t.timeZone,returnMeshObjectId:!1,displayRefreshVersion:s,currentUser:t.currentUser},strategy:{type:"feature"},factory:{symbology:i,labels:{type:"label",classes:[]},referenceScale:a}},expressionProperties:{timeExtent:null}}}get hasRequiredSupport(){return!0}get timeOptions(){return this.layer}addFilters(e){return e}getUpdateHashProperties(){return this.layer.destroyed?[]:[()=>this.layer.apiKey,()=>this.layer.customParameters,()=>this.layer.definitionExpression,()=>this.layer.gdbVersion,()=>this.layer.historicMoment,()=>this.layer.outFields]}getRenderer(){return null}setGraphicOrigin(e){e.origin=this.layer.graphicOrigin}_createServiceInfo(r){const a=this.layer,o=a.fieldsIndex.toJSON();o.fields.push(...u);const{capabilities:n,editingInfo:l,globalIdField:p,datesInUnknownTimezone:c,dateFieldsTimeZone:m,subtypeField:d}=a,y=i(a),h=a.timeInfo?.toJSON(),f=a.spatialReference.toJSON(),g=e(this.layer.parsedUrl),S=this.layer.objectIdField,R=t(g.path),F=r.spatialReference.toJSON();return{type:"feature-service",source:g,isSourceHosted:R,orderByFields:S,outSpatialReference:F,metadata:{timeReferenceUnknownClient:c,dateFieldsTimeZone:m,subtypeField:d,globalIdField:p,fieldsIndex:o,geometryType:y,featureIdInfo:s(a),timeInfo:h,spatialReference:f,outSpatialReference:F,subtypes:this.layer.subtypes?.map(e=>e.toJSON()),typeIdField:null,types:null,layerType:a.type,hasM:!1,hasZ:!1},queryMetadata:{supportsFormatPBF:n.query.supportsFormatPBF,supportsQuantization:!1,maxRecordCount:n.query.maxRecordCount,tileMaxRecordCount:n.query.tileMaxRecordCount,supportsCompactGeometry:n.query.supportsCompactGeometry,supportsDefaultSpatialReference:n.query.supportsDefaultSpatialReference,supportsMaxRecordCountFactor:n.query.supportsMaxRecordCountFactor,supportsCentroidOnDegeneratedQuantizedGeometry:n.query.supportsCentroidOnDegeneratedQuantizedGeometry,supportsDegeneratedQuantizedGeometry:n.query.supportsDegeneratedQuantizedGeometry,lastEditDate:l?.lastEditDate?.getTime(),supportsReturnExceededLimitGeometries:n.query.supportsReturnExceededLimitGeometries}}}async _fetchDimensionDataElementRequest(e,t){const r={cimAnalyzer:e.cimAnalyzer,cimResourceManager:e.cimResourceManager,store:e.store,scaleExpression:null},s=this.layer,i=await s.fetchDataElement(),a=m(i);return{type:"dimension-data-element-response",dataElement:i,meshes:await p(i,r),referenceScale:a}}}export{d as DimensionLayerAdapter};
