/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{clone as e}from"../../../../../core/lang.js";import{sqlAnd as r}from"../../../../../core/sql.js";import{isHostedAgolService as t}from"../../../../../layers/support/arcgisLayerUrl.js";import{getEffectiveFeatureReduction as i}from"./featureReductionUtils.js";import{createFeatureIdInfo as s}from"./featureServiceUtils.js";import{addFloorFilter as a,hasFloorFilter as o}from"./floorFilterUtils.js";import{getServiceGeometryType as l}from"./geometryUtils.js";import{getFeatureReductionDeconflictionEnabled as n,getLayerDeconflictionEnabled as y,createLabelVVEvaluator as p}from"./labelingUtils.js";import{ExceedsLimitCache as d}from"../schema/ExceedsLimitCache.js";import{createSnapshotInfo as c,createFeatureSourceSchema as u}from"../schema/SourceSchema.js";import{createSimpleProcessorSchema as m}from"../schema/processor/SimpleProcessorSchema.js";import{isRendererSupported as h}from"../support/rendererUtils.js";class f{constructor(e){this.layer=e,this._cache=new d}getLabelingDeconflictionInfo(e){const r=this.layer,t=n(r,e)??y(r),s=i(r,e),a=[...r.labelingInfo||[],...s?.labelingInfo||[]];return[{vvEvaluators:{0:p(r.renderer)},deconflictionEnabled:t,labelingInfo:a}]}async createSourceSchema(e,t){const i=this._createServiceInfo(e),s=null!=this.layer.editingInfo?.lastEditDate,a=this.layer.refreshInterval>0,o=!s&&a,l=c(i.isSourceHosted,o,this.layer.capabilities,i.metadata.geometryType,e.extent,this.layer.fullExtent),n=null!=this.layer.subtypeCode?`${this.layer.subtypeField} = ${this.layer.subtypeCode}`:null,y=r(this.layer.definitionExpression,n);return u(i,l,{definitionExpression:y,queryScaleRanges:[],displayFilterEnabled:e.displayFilterEnabled,displayFilterInfo:this.layer.displayFilterInfo,customParameters:this.layer.customParameters,gdbVersion:this.layer.gdbVersion,historicMoment:this.layer.historicMoment,timeExtent:this.layer.timeExtent,apiKey:this.layer.apiKey,sourceRefreshVersion:t,availableFields:e.availableFields,cache:this._cache})}createProcessorSchema(e,r,t){const{fields:s,renderer:a,geometryType:o,labelingInfo:l,labelsVisible:n,orderBy:y,objectIdField:p,trackInfo:d}=this.layer,c={fields:s.map(e=>e.toJSON()),renderer:a?.clone(),labelingInfoSource:this.layer.id,featureReduction:i(this.layer,r),geometryType:o,labelingInfo:l,labelsVisible:n,objectIdField:p,orderBy:y??"default",trackInfo:d};return m(e,r,c,t)}get hasRequiredSupport(){return h(this.layer.renderer)}get timeOptions(){return this.layer}addFilters(e,r){return a(this.layer,e,r)}getUpdateHashProperties(e){return this.layer.destroyed?[]:[()=>this.layer.apiKey,()=>this.layer.customParameters,()=>this.layer.definitionExpression,()=>i(this.layer,e),()=>o(this.layer,e)?e.floors:null,()=>this.layer.gdbVersion,()=>this.layer.historicMoment,()=>this.layer.labelsVisible?this.layer.labelingInfo:null,()=>this.layer.orderBy,()=>this.layer.outFields,()=>this.layer.renderer,()=>this.layer.subtypeCode,()=>this.layer.trackInfo]}setGraphicOrigin(e){e.origin=this.layer.graphicOrigin}setAggregateGraphicOrigin(e){e.origin=this.layer.aggregateGraphicOrigin}setTrackGraphicOrigin(e){e.origin=this.layer.trackGraphicOrigin}_createServiceInfo(r){const i=this.layer,{capabilities:a,editingInfo:o,typeIdField:n,globalIdField:y,datesInUnknownTimezone:p,dateFieldsTimeZone:d,orderBy:c,subtypeField:u}=i,m=i.fieldsIndex.toJSON(),h=l(i),f=i.timeInfo?.toJSON(),g=i.spatialReference.toJSON(),b=i.types?.map(e=>e.toJSON()),I=e(this.layer.parsedUrl);this.layer.dynamicDataSource&&(I.query={layer:JSON.stringify({source:this.layer.dynamicDataSource})});let S=this.layer.objectIdField;if(c?.length){const e=!c[0].valueExpression&&c[0].field;e&&(S=e)}const F=t(I.path),O=r.spatialReference.toJSON();return{type:"feature-service",source:I,isSourceHosted:F,orderByFields:S,outSpatialReference:O,metadata:{typeIdField:n??void 0,types:b,timeReferenceUnknownClient:p,dateFieldsTimeZone:d,subtypeField:u,globalIdField:y,fieldsIndex:m,geometryType:h,featureIdInfo:s(i),timeInfo:f,spatialReference:g,outSpatialReference:O,subtypes:this.layer.subtypes?.map(e=>e.toJSON())},queryMetadata:{maxRecordCount:a.query.maxRecordCount,supportsCompactGeometry:a.query.supportsCompactGeometry,supportsDefaultSpatialReference:a.query.supportsDefaultSpatialReference,supportsFormatPBF:a.query.supportsFormatPBF,supportsMaxRecordCountFactor:a.query.supportsMaxRecordCountFactor,supportsQuantization:a.query.supportsQuantization,supportsCentroidOnDegeneratedQuantizedGeometry:a.query.supportsCentroidOnDegeneratedQuantizedGeometry,supportsDegeneratedQuantizedGeometry:a.query.supportsDegeneratedQuantizedGeometry,lastEditDate:o?.lastEditDate?.getTime()}}}}export{f as FeatureLayerAdapter};
