/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as e}from"tslib";import r from"../../core/Error.js";import{isBlobProtocol as i}from"../../core/urlUtils.js";import{property as t,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{addLayerUnsupportedError as u}from"../../webdoc/support/unsupportedErrors.js";import{reader as w}from"../../core/accessorSupport/decorators/reader.js";import{writer as b}from"../../core/accessorSupport/decorators/writer.js";const g=g=>{const T=g;let v=class extends T{constructor(){super(...arguments),this.persistenceEnabled=!0,this.title=null}readId(e,r,i){return"Group Layer"===i?.portalItem?.type?void 0:e}writeListMode(e,r,i,t){(t&&"ground"===t.layerContainerType||e&&l(this,i,{},t))&&(r[i]=e)}writeOperationalLayerType(e,r,i){e&&(r[i]=e)}writeTitle(e,r){r.title=e??"Layer"}readVisibilityTimeExtent(e){return e?d.fromArray(e):null}writeVisibilityTimeExtent(e,i,t,o){e&&"tables"!==o.layerContainerType&&(e.isEmpty?o?.messages&&o.messages.push(new r("layer:invalid-visibilityTimeExtent","visibilityTimeExtent cannot be empty")):i[t]=e.toArray())}read(e,r){r&&(r.layer=this),p(this,e,r=>super.read(e,r),r)}write(e,t){if(!this.persistenceEnabled&&!t?.ignorePersistenceEnabled)return null;if(t?.origin){const e=`${t.origin}/${t.layerContainerType||"operational-layers"}`,r=y[e];let i=!!r?.[this.operationalLayerType];if("ArcGISTiledElevationServiceLayer"===this.operationalLayerType&&"web-scene/operational-layers"===e&&(i=!1),"ArcGISDimensionLayer"===this.operationalLayerType&&"web-map/operational-layers"===e&&(i=!1),!i)return u(t,this),null}const o=super.write(e,{...t,layer:this}),s=!!t&&!!t.messages&&!!t.messages.filter(e=>e instanceof r&&"web-document-write:property-required"===e.name).length;return i(o?.url)?(t?.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([t({type:String,json:{write:{ignoreOrigin:!0},origins:{"web-scene":{write:{isRequired:!0,ignoreOrigin:!0}},"portal-item":{write:!1}}}})],v.prototype,"id",void 0),e([w("id",["id"])],v.prototype,"readId",null),e([t(m)],v.prototype,"listMode",void 0),e([b("listMode")],v.prototype,"writeListMode",null),e([t({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}}}}})],v.prototype,"operationalLayerType",void 0),e([b("operationalLayerType")],v.prototype,"writeOperationalLayerType",null),e([t(c)],v.prototype,"opacity",void 0),e([t({type:Boolean,readOnly:!1})],v.prototype,"persistenceEnabled",void 0),e([t({type:String,json:{write:{ignoreOrigin:!0,writerEnsuresNonNull:!0},origins:{"web-scene":{write:{isRequired:!0,ignoreOrigin:!0,writerEnsuresNonNull:!0}},"portal-item":{write:!1}}},value:"Layer"})],v.prototype,"title",void 0),e([b("title"),b(["web-scene"],"title")],v.prototype,"writeTitle",null),e([t({type:d,json:{origins:{"web-scene":{write:{layerContainerTypes:a}}}}})],v.prototype,"visibilityTimeExtent",void 0),e([w("visibilityTimeExtent")],v.prototype,"readVisibilityTimeExtent",null),e([b(["portal-item","web-map","web-scene"],"visibilityTimeExtent",{visibilityTimeExtent:{type:[[s,n]]}})],v.prototype,"writeVisibilityTimeExtent",null),e([t({type:Boolean,json:{name:"visibility",write:{layerContainerTypes:a}}})],v.prototype,"visible",void 0),v=e([o("esri.layers.mixins.OperationalLayer")],v),v};export{g as OperationalLayer};
