/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import r from"../../core/Error.js";import{isBlobProtocol as t}from"../../core/urlUtils.js";import{property as i,subclass as o}from"../../core/accessorSupport/decorators.js";import{Integer as s,Null as n}from"../../core/accessorSupport/ensureType.js";import{excludeTables as a}from"../../core/accessorSupport/layerContainerType.js";import{readLoadable as p}from"../../core/accessorSupport/read.js";import{willPropertyWrite as l}from"../../core/accessorSupport/write.js";import{supportedTypes as y}from"./operationalLayers.js";import{listMode as m,opacity as c}from"../support/commonProperties.js";import d from"../../time/TimeExtent.js";import{reader as u}from"../../core/accessorSupport/decorators/reader.js";import{writer as w}from"../../core/accessorSupport/decorators/writer.js";const b=b=>{const g=b;let T=class extends g{constructor(){super(...arguments),this.persistenceEnabled=!0,this.title=null}readId(e,r,t){return"Group Layer"===t?.portalItem?.type?void 0:e}writeListMode(e,r,t,i){(i&&"ground"===i.layerContainerType||e&&l(this,t,{},i))&&(r[t]=e)}writeOperationalLayerType(e,r,t){e&&(r[t]=e)}writeTitle(e,r){r.title=e??"Layer"}readVisibilityTimeExtent(e){return e?d.fromArray(e):null}writeVisibilityTimeExtent(e,t,i,o){e&&"tables"!==o.layerContainerType&&(e.isEmpty?o?.messages&&o.messages.push(new r("layer:invalid-visibilityTimeExtent","visibilityTimeExtent cannot be empty")):t[i]=e.toArray())}read(e,r){r&&(r.layer=this),p(this,e,r=>super.read(e,r),r)}write(e,i){if(!this.persistenceEnabled&&!i?.ignorePersistenceEnabled)return null;if(i?.origin){const e=`${i.origin}/${i.layerContainerType||"operational-layers"}`,t=y[e];let o=!!t?.[this.operationalLayerType];if("ArcGISTiledElevationServiceLayer"===this.operationalLayerType&&"web-scene/operational-layers"===e&&(o=!1),"ArcGISDimensionLayer"===this.operationalLayerType&&"web-map/operational-layers"===e&&(o=!1),!o)return i.messages?.push(new r("layer:unsupported",`Layers (${this.title}, ${this.id}) of type '${this.declaredClass}' are not supported in the context of '${e}'`,{layer:this})),null}const o=super.write(e,{...i,layer:this}),s=!!i&&!!i.messages&&!!i.messages.filter(e=>e instanceof r&&"web-document-write:property-required"===e.name).length;return t(o?.url)?(i?.messages?.push(new r("layer:invalid-url",`Layer (${this.title}, ${this.id}) of type '${this.declaredClass}' using a Blob URL cannot be written to web scenes and web maps`,{layer:this})),null):!this.url&&s?null:o}beforeSave(){}};return e([i({type:String,json:{write:{ignoreOrigin:!0},origins:{"web-scene":{write:{isRequired:!0,ignoreOrigin:!0}},"portal-item":{write:!1}}}})],T.prototype,"id",void 0),e([u("id",["id"])],T.prototype,"readId",null),e([i(m)],T.prototype,"listMode",void 0),e([w("listMode")],T.prototype,"writeListMode",null),e([i({type:String,readOnly:!0,json:{read:!1,write:{target:"layerType",ignoreOrigin:!0},origins:{"portal-item":{write:!1},"web-scene":{name:"layerType",read:!1,write:{enabled:!0,ignoreOrigin:!0,layerContainerTypes:a,isRequired:!0}}}}})],T.prototype,"operationalLayerType",void 0),e([w("operationalLayerType")],T.prototype,"writeOperationalLayerType",null),e([i(c)],T.prototype,"opacity",void 0),e([i({type:Boolean,readOnly:!1})],T.prototype,"persistenceEnabled",void 0),e([i({type:String,json:{write:{ignoreOrigin:!0,writerEnsuresNonNull:!0},origins:{"web-scene":{write:{isRequired:!0,ignoreOrigin:!0,writerEnsuresNonNull:!0}},"portal-item":{write:!1}}},value:"Layer"})],T.prototype,"title",void 0),e([w("title"),w(["web-scene"],"title")],T.prototype,"writeTitle",null),e([i({type:d,json:{origins:{"web-scene":{write:{layerContainerTypes:a}}}}})],T.prototype,"visibilityTimeExtent",void 0),e([u("visibilityTimeExtent")],T.prototype,"readVisibilityTimeExtent",null),e([w(["portal-item","web-map","web-scene"],"visibilityTimeExtent",{visibilityTimeExtent:{type:[[s,n]]}})],T.prototype,"writeVisibilityTimeExtent",null),e([i({type:Boolean,json:{name:"visibility",write:{layerContainerTypes:a}}})],T.prototype,"visible",void 0),T=e([o("esri.layers.mixins.OperationalLayer")],T),T};export{b as OperationalLayer};
