/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as t}from"tslib";import{JSONSupport as n}from"../../core/JSONSupport.js";import{clone as e}from"../../core/lang.js";import{property as r,subclass as o}from"../../core/accessorSupport/decorators.js";import i from"./RasterFunctionTemplate.js";import{reader as s}from"../../core/accessorSupport/decorators/reader.js";import{writer as a}from"../../core/accessorSupport/decorators/writer.js";import{enumeration as u}from"../../core/accessorSupport/decorators/enumeration.js";var c;const p=new Set(["raster","raster2","dem","fillraster"]),f=new Set(["rasters"]),m=t=>t?.rasterFunction?g.fromJSON(t):t,l=t=>t&&t instanceof g?t.toJSON():t,y=t=>t?.functionName&&!t.declaredClass,F=t=>y(t)?new g(t):t,h=t=>{if(null==t)return null;t=e(t);const n={};for(const e of Object.keys(t))p.has(e.toLowerCase())?n[e]=m(t[e]):f.has(e.toLowerCase())&&Array.isArray(t[e])?n[e]=t[e].map(m):n[e]=t[e];return n},d=t=>t?i.fromJSON({type:"RasterFunctionTemplate",...t}):void 0,N={types:{key:"type",base:null,typeMap:{RasterFunctionTemplate:i}},json:{write:!0,name:"rasterFunctionDefinition",read:d}};let g=c=class extends n{constructor(t){super(t),this.functionName=null,this.outputPixelType="unknown",this.variableName=null,this.functionDefinition=null}set functionArguments(t){if(t){const n=Object.keys(t);if(n.some(n=>p.has(n.toLowerCase())&&y(t[n]))||n.some(n=>f.has(n.toLowerCase())&&Array.isArray(t[n])&&t[n].some(t=>y(t)))){t=e(t);for(const e of n)p.has(e.toLowerCase())?t[e]=F(t[e]):f.has(e.toLowerCase())&&Array.isArray(t[e])&&(t[e]=t[e].map(t=>F(t)))}}this._set("functionArguments",t)}readFunctionArguments(t){return h(t)}writeFunctionArguments(t,n,e){const r={};for(const o of Object.keys(t))p.has(o.toLowerCase())?r[o]=l(t[o]):f.has(o.toLowerCase())&&Array.isArray(t[o])?r[o]=t[o].map(l):r[o]=l(t[o]);n[e]=r}readFunctionName(t,n){const e=n.rasterFunctionInfos,r=n.name;return r||(e?.length&&"None"!==e[0].name?e[0].name:n.rasterFunction||n.rasterFunctionDefinition?.name)}get rasterFunctionDefinition(){return this.functionDefinition?.toJSON()}set rasterFunctionDefinition(t){this.functionDefinition=d(t)}get hasClipFunction(){return this.rasterFunctionDefinition?JSON.stringify(this.rasterFunctionDefinition).includes('"type":"ClipFunction"'):JSON.stringify(this).includes('"rasterFunction":"Clip"')}clone(){return new c({functionName:this.functionName,functionArguments:e(this.functionArguments),outputPixelType:this.outputPixelType,variableName:this.variableName,rasterFunctionDefinition:e(this.rasterFunctionDefinition)})}};t([r({json:{type:Object,name:"rasterFunctionArguments"}})],g.prototype,"functionArguments",null),t([s("functionArguments")],g.prototype,"readFunctionArguments",null),t([a("functionArguments")],g.prototype,"writeFunctionArguments",null),t([r({json:{type:String,write:{target:"rasterFunction"}}})],g.prototype,"functionName",void 0),t([s("functionName",["rasterFunction","rasterFunctionInfos","rasterFunctionDefinition"])],g.prototype,"readFunctionName",null),t([u({C128:"c128",C64:"c64",F32:"f32",F64:"f64",S16:"s16",S32:"s32",S8:"s8",U1:"u1",U16:"u16",U2:"u2",U32:"u32",U4:"u4",U8:"u8",UNKNOWN:"unknown"},{ignoreUnknown:!1,default:"unknown"})],g.prototype,"outputPixelType",void 0),t([r({type:String,json:{read:!0,write:!0}})],g.prototype,"variableName",void 0),t([r()],g.prototype,"rasterFunctionDefinition",null),t([r(N)],g.prototype,"functionDefinition",void 0),t([r()],g.prototype,"hasClipFunction",null),g=c=t([o("esri.layers.support.RasterFunction")],g);export{g as default};
