/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../core/has","../../core/Error","../../core/maybe","../HeightModelInfo","../../layers/support/arcgisLayerUrl"],(function(e,t,n,i,r,o){"use strict";function a(e,t){if(!e)return null;if(!h(e))return new n("webscene:unsupported-height-model-info","The vertical coordinate system of the scene is not supported",{heightModelInfo:e});const i=e.heightUnit,o=r.deriveUnitFromSR(e,t).heightUnit;return i!==o?new n("webscene:incompatible-height-unit",`The vertical units of the scene (${i}) must match the horizontal units of the scene (${o})`,{verticalUnit:i,horizontalUnit:o}):null}function s(e,t,i){const o=d(e),a=t,s=l(o,a,i);if(o){const t=r.deriveUnitFromSR(o,e.spatialReference).heightUnit;if(!i&&t!==o.heightUnit){const e=new n("layerview:unmatched-height-unit",`The vertical units of the layer must match the horizontal units (${t})`,{horizontalUnit:t});return new n("layerview:unsupported-height-model-info","The vertical coordinate system of the layer is not supported",{heightModelInfo:o,error:e})}}if(!u(e)||s===c.Unsupported)return new n("layerview:unsupported-height-model-info","The vertical coordinate system of the layer is not supported",{heightModelInfo:o});switch(s){case c.Units:{const e=o.heightUnit||"unknown",t=a.heightUnit||"unknown",i=new n("layerview:incompatible-height-unit",`The vertical units of the layer (${e}) must match the vertical units of the scene (${t})`,{layerUnit:e,sceneUnit:t});return new n("layerview:incompatible-height-model-info","The vertical coordinate system of the layer is incompatible with the scene",{layerHeightModelInfo:o,sceneHeightModelInfo:a,error:i})}case c.HeightModel:{const e=o.heightModel||"unknown",t=a.heightModel||"unknown",i=new n("layerview:incompatible-height-model",`The height model of the layer (${e}) must match the height model of the scene (${t})`,{layerHeightModel:e,sceneHeightModel:t});return new n("layerview:incompatible-height-model-info","The vertical coordinate system of the layer is incompatible with the scene",{layerHeightModelInfo:o,sceneHeightModelInfo:a,error:i})}case c.CRS:{const e=o.vertCRS||"unknown",t=a.vertCRS||"unknown",i=new n("layerview:incompatible-vertical-datum",`The vertical datum of the layer (${e}) must match the vertical datum of the scene (${t})`,{layerDatum:e,sceneDatum:t});return new n("layerview:incompatible-height-model-info","The vertical coordinate system of the layer is incompatible with the scene",{layerHeightModelInfo:o,sceneHeightModelInfo:a,error:i})}}return null}function l(e,t,n){if(!h(e)||!h(t))return c.Unsupported;if(null==e||null==t)return c.Ok;if(!n&&e.heightUnit!==t.heightUnit)return c.Units;if(e.heightModel!==t.heightModel)return c.HeightModel;switch(e.heightModel){case"gravity-related-height":return c.Ok;case"ellipsoidal":return e.vertCRS===t.vertCRS?c.Ok:c.CRS;default:return c.Unsupported}}var c;function h(e){return null==e||null!=e.heightModel&&null!=e.heightUnit}function u(e){return"heightModelInfo"in e&&null!=e.heightModelInfo||null!=e.spatialReference||!p(e)}function d(e){const t=e.url&&o.parse(e.url);return!(null==(e.spatialReference&&e.spatialReference.vcsWkid)&&i.isSome(t)&&"ImageServer"===t.serverType)&&f(e)&&e.heightModelInfo?e.heightModelInfo:p(e)?r.deriveUnitFromSR(v,e.spatialReference):null}function f(e){return"heightModelInfo"in e}function g(e){if("unknown"===e.type||!("capabilities"in e))return!1;switch(e.type){case"csv":case"feature":case"geojson":case"subtype-group":case"ogc-feature":case"wfs":return!0;default:return!1}}function p(e){return g(e)?!!(e.capabilities&&e.capabilities.data&&e.capabilities.data.supportsZ):y(e)}function m(e){return null!=e.layers||y(e)||g(e)||f(e)}function y(e){switch(e.type){case"building-scene":case"elevation":case"integrated-mesh":case"point-cloud":case"scene":case"voxel":return!0;case"line-of-sight":case"base-dynamic":case"base-elevation":case"base-tile":case"bing-maps":case"csv":case"geojson":case"feature":case"subtype-group":case"geo-rss":case"graphics":case"group":case"imagery":case"imagery-tile":case"kml":case"map-image":case"map-notes":case"media":case"ogc-feature":case"open-street-map":case"route":case"stream":case"tile":case"unknown":case"unsupported":case"vector-tile":case"wcs":case"web-tile":case"wfs":case"wms":case"wmts":case null:return!1}return!1}!function(e){e[e.Ok=0]="Ok",e[e.Units=1]="Units",e[e.HeightModel=2]="HeightModel",e[e.CRS=3]="CRS",e[e.Unsupported=4]="Unsupported"}(c||(c={}));const v=new r({heightModel:"gravity-related-height"});e.deriveHeightModelInfoFromLayer=d,e.rejectLayerError=s,e.supportsHeightModelInfo=m,e.validateWebSceneError=a,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
