import{__decorate as e}from"tslib";import{InvalidOperationError as r}from"../InvalidOperationError.js";import{serializable as t}from"../support/Serializable.js";import{watchEach as s}from"../support/observableUtils.js";import{isBuildingSceneLayer as i}from"../utilities/_layers.js";import{flatten as a}from"../utilities/array.js";import{checkArg as l}from"../utilities/checkArg.js";import{LayerExtension as o,LayerExtensionSchema as n}from"./_LayerExtension.js";import{SublayerExtension as y}from"./_SublayerExtension.js";import{SublayerExtensionCollectionBase as u}from"./support/_SublayerExtensionCollection.js";const p="SublayerExtension collection for BuildingLayerExtension is readonly";let d=class extends o{get layer(){return super.layer}get sublayerExtensions(){return super.sublayerExtensions}get supportsSublayers(){return!0}get _layerView(){return this.layer&&this.mapExtension?._allLayerViews.find((e=>e.layer===this.layer))}_deferredSublayerProperties;constructor(e){super(e),this._watchHandles.push(s(this,"layer.allSublayers.[].outFields",(()=>{this.layer.outFields=[...new Set(a(this.layer.allSublayers.toArray().filter((e=>"building-component"===e.type)).map((e=>e.outFields?e.outFields.includes("*")?e.fields?.map((e=>e.name))??[]:e.outFields:[]))))]})))}_createSublayerExtension(e){return y.factory.create(e)}_applyLayerProperties(e,r){return l("layerJson",e).isNotMissing(),l("layerJson.layerType",e.layerType).satisfies((e=>!e||"BuildingSceneLayer"===e)),l("layer",r).isNotMissing().satisfies(i),super._applyLayerProperties(e,r)}async _onInitialize(){await super._onInitialize(),this._deferredSublayerProperties&&(this.assignProperties({layer:{layerType:"BuildingSceneLayer",sublayers:this._deferredSublayerProperties}}),this._deferredSublayerProperties=void 0)}_createSublayerExtensionCollection(){return new h(this)}_isSupportedLayer(e){return i(e)}_createSchema(){return new c(this)}async _applyPortalItemProperties(e){if("Scene Service"!==e.type)throw new Error(`Cannot create Scene Layer from Portal item that has type: ${e.type}`);if(!e.typeKeywords.includes("Building"))throw new Error("Cannot create building scene layer from Portal item that does not reference a building scene layer.");this.layer.url=e.url||this.layer.url}_capabilities(){return{...super._capabilities(),supportsStandardizedQueries:!0}}_getSerializableProperties(){const e=super._getSerializableProperties();return{...e,layer:{...this._toPropertyDef(e.layer),default:{layerType:"BuildingSceneLayer"},deserialize:r=>{if(this._toPropertyDef(e.layer).deserialize(r),r&&!i(r)&&r.sublayers&&!this.layer?.sublayers){this._deferredSublayerProperties=this._deferredSublayerProperties||[];for(const e of r.sublayers){const r=this._deferredSublayerProperties.findIndex((r=>r.title===e.title));r>=0?this._deferredSublayerProperties[r]={...this._deferredSublayerProperties[r],...e}:this._deferredSublayerProperties.push({...e})}}}}}}};d=e([t],d);export{d as BuildingSceneLayerExtension};let c=class extends n{_getPropertyBindings(){return{spatialReference:"spatialReference"}}_setSetting(e,t){if(this._layerBindings.has(e))throw new r("This schema property is read-only.");super._setSetting(e,t)}};c=e([t],c);export{c as BuildingSceneLayerReadOnlySchema};class h extends u{constructor(e){super(e,"layer.sublayers"),this._layerExtension=e}add(e,t){if(l("sublayerX",e).isNotMissing(),e.sublayer&&this._parent.layer.sublayers&&!this._parent.layer.sublayers.includes(e.sublayer))throw new r(p);return super.add(e,t)}removeAt(e){throw new r(p)}reorder(e,t){throw new r(p)}reverse(){throw new r(p)}sort(e){throw new r(p)}splice(e,t,...s){throw new r(p)}_createSublayerExtension(e){return this._parent._createSublayerExtension(e)}}