/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
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 p}from"../../core/accessorSupport/layerContainerType.js";import{readLoadable as a}from"../../core/accessorSupport/read.js";import{willPropertyWrite as l}from"../../core/accessorSupport/write.js";import{listMode as y,opacity as m}from"../support/commonProperties.js";import{isLayerSupportedForWriteContext as u}from"../support/layersMapping.js";import d from"../../time/TimeExtent.js";import{addLayerUnsupportedError as c}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 f=class extends T{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),a(this,e,r=>super.read(e,r),r)}write(e,i){if(!this.persistenceEnabled&&!i?.ignorePersistenceEnabled)return null;if(i?.origin){if(!u(i,this.operationalLayerType,this.type))return c(i,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}}}})],f.prototype,"id",void 0),e([w("id",["id"])],f.prototype,"readId",null),e([i(y)],f.prototype,"listMode",void 0),e([b("listMode")],f.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:p,isRequired:!0}}}}})],f.prototype,"operationalLayerType",void 0),e([b("operationalLayerType")],f.prototype,"writeOperationalLayerType",null),e([i(m)],f.prototype,"opacity",void 0),e([i({type:Boolean,readOnly:!1})],f.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"})],f.prototype,"title",void 0),e([b("title"),b(["web-scene"],"title")],f.prototype,"writeTitle",null),e([i({type:d,json:{origins:{"web-scene":{write:{layerContainerTypes:p}}}}})],f.prototype,"visibilityTimeExtent",void 0),e([w("visibilityTimeExtent")],f.prototype,"readVisibilityTimeExtent",null),e([b(["portal-item","web-map","web-scene"],"visibilityTimeExtent",{visibilityTimeExtent:{type:[[s,n]]}})],f.prototype,"writeVisibilityTimeExtent",null),e([i({type:Boolean,json:{name:"visibility",write:{layerContainerTypes:p}}})],f.prototype,"visible",void 0),f=e([o("esri.layers.mixins.OperationalLayer")],f),f};export{g as OperationalLayer};
