/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import{JSONSupport as t}from"../../core/JSONSupport.js";import{property as r,subclass as o}from"../../core/accessorSupport/decorators.js";import{getPixelValueRange as i}from"../raster/formats/pixelRangeUtils.js";import{isSupportedRendererType as n,combineRenderingRules as s,convertRendererToRenderingRule as a}from"./imageryRendererUtils.js";import p from"./MosaicRule.js";import{interpolationKebab as l,noDataInterpretationKebab as c,pixelTypeKebabDict as m}from"./rasterEnums.js";import u from"./RasterFunction.js";import{writer as y}from"../../core/accessorSupport/decorators/writer.js";let d=class extends t{constructor(){super(...arguments),this.layer=null,this.requestRawData=!1,this.compression=void 0,this.lercVersion=2}get adjustAspectRatio(){return this.layer.adjustAspectRatio}writeAdjustAspectRatio(e,t,r){this.layer.version<10.3||(t[r]=e)}get bandIds(){return this.layer.bandIds}get compressionQuality(){return this.layer.compressionQuality}writeCompressionQuality(e,t,r){this.format&&this.format.toLowerCase().includes("jpg")&&null!=e&&(t[r]=e)}get compressionTolerance(){return this.layer.compressionTolerance}writeCompressionTolerance(e,t,r){"lerc"===this.format&&null!=e&&(t[r]=e)}get format(){const e=this.layer.renderer?.type;return this.requestRawData||"vector-field"===e||"flow"===e?"lerc":this.layer.format}get interpolation(){return this.layer.interpolation}get noData(){return this.layer.noData}get noDataInterpretation(){return this.layer.noDataInterpretation}get pixelType(){const{layer:e}=this;return e.pixelType!==e.serviceRasterInfo.pixelType?e.pixelType:void 0}writeLercVersion(e,t,r){"lerc"===this.format&&this.layer.version>=10.5&&(t[r]=e)}get version(){const e=this.layer;return e.commitProperty("bandIds"),e.commitProperty("format"),e.commitProperty("compressionQuality"),e.commitProperty("compressionTolerance"),e.commitProperty("interpolation"),e.commitProperty("noData"),e.commitProperty("noDataInterpretation"),e.commitProperty("mosaicRule"),e.commitProperty("rasterFunction"),e.commitProperty("adjustAspectRatio"),e.commitProperty("pixelFilter"),e.commitProperty("pixelType"),e.commitProperty("definitionExpression"),e.commitProperty("multidimensionalSubset"),(this._get("version")||0)+1}set version(e){this._set("version",e)}get mosaicRule(){const e=this.layer;let t=e.mosaicRule;const r=e.definitionExpression;return t?r&&r!==t.where&&(t=t.clone(),t.where=r):r&&(t=new p({where:r})),t}get rasterFunction(){const e=this.layer;let{rasterFunction:t,rasterInfo:r}=e;t&&"lerc"===this.format&&1===r?.bandCount&&r.colormap&&(t=f(t,r.pixelType));const o=e.multidimensionalSubset?.areaOfInterest;return o&&(t=w(t,o)),this.requestRawData||!e.isRenderedFormat||e.pixelFilter||"vector-field"===e.renderer?.type||(t=this.combineRendererWithRenderingRule(t)),t}combineRendererWithRenderingRule(e){const t=this.layer,{rasterInfo:r,renderer:o}=t;if(e=e||t.rasterFunction,!o||!n(o))return e;return s(a(o,{rasterAttributeTable:r.attributeTable,pixelType:r.pixelType,dataType:r.dataType,bandNames:r.bandInfos.map(({name:e})=>e),convertColorRampToColormap:t.version<10.6,convertToRFT:!!e?.rasterFunctionDefinition,bandCount:r.bandCount}),e)}};function w(e,t){const r=new u({functionName:"Clip",functionArguments:{ClippingGeometry:t.toJSON(),ClippingType:1}});return s(r,e)}function f(e,t){const[r,o]=i(t),n=new u({functionName:"Stretch",functionArguments:{StretchType:5,UseGamma:!1,Min:r,Max:o,Statistics:[[r,o,1,1]]}});return s(n,e)}e([r()],d.prototype,"layer",void 0),e([r()],d.prototype,"requestRawData",void 0),e([r({json:{write:!0}})],d.prototype,"adjustAspectRatio",null),e([y("adjustAspectRatio")],d.prototype,"writeAdjustAspectRatio",null),e([r({json:{write:!0}})],d.prototype,"bandIds",null),e([r({json:{write:!0}})],d.prototype,"compression",void 0),e([r({json:{write:!0}})],d.prototype,"compressionQuality",null),e([y("compressionQuality")],d.prototype,"writeCompressionQuality",null),e([r({json:{write:!0}})],d.prototype,"compressionTolerance",null),e([y("compressionTolerance")],d.prototype,"writeCompressionTolerance",null),e([r({json:{write:!0}})],d.prototype,"format",null),e([r({type:String,json:{read:{reader:l.read},write:{writer:l.write}}})],d.prototype,"interpolation",null),e([r({json:{write:!0}})],d.prototype,"noData",null),e([r({type:String,json:{read:{reader:c.read},write:{writer:c.write}}})],d.prototype,"noDataInterpretation",null),e([r({type:m.apiValues,json:{read:m.read,write:m.write}})],d.prototype,"pixelType",null),e([r({json:{write:!0}})],d.prototype,"lercVersion",void 0),e([y("lercVersion")],d.prototype,"writeLercVersion",null),e([r({type:Number})],d.prototype,"version",null),e([r({json:{write:!0}})],d.prototype,"mosaicRule",null),e([r({json:{write:!0,name:"renderingRule"}})],d.prototype,"rasterFunction",null),d=e([o("esri.layers.support.ExportImageServiceParameters")],d);export{d as ExportImageServiceParameters};
