    import {defaultValue, toJSON} from '../../../util'
    import { Extent } from '../../../base/geometry'
    import IGSSceneSubLayer from './IGSSceneSubLayer';

    /**
     * 场景对象
     * @class Scene
     * @moduleEX LayerModule
     * @param {Object} options 构造参数
     * @param {Number} [options.sceneIndex = 0] 该场景在场景文档中的索引
     * @param {String} [options.sceneName] 场景名
     * @param {String} [options.sceneMode] 场景类型
     * @param {Extent} [options.sceneMode] 场景包围盒
     * @param {Array} [options.sublayers] 场景中包含的图层列表
     * @param {IGSSceneLayer} [options.layer] 场景所属的场景服务图层
     * @param {Array} [options.extendedProps] 扩展属性
     */
    class Scene {
      constructor(options) {
        options = defaultValue(options, {})

        /**
         * 该场景在场景文档中的索引
         * @member {Number} Scene.prototype.sceneIndex
         */
        this.sceneIndex = defaultValue(options.sceneIndex, 0)
        /**
         * 场景名
         * @member {String} Scene.prototype.sceneName
         */
        this.sceneName = defaultValue(options.sceneName, undefined)
        /**
         * 场景类型
         * @member {String} Scene.prototype.sceneMode
         */
        this.sceneMode = defaultValue(options.sceneMode, undefined)
        /**
         * 场景包围盒
         * @member {Extent} Scene.prototype.sceneRange
         */
        this.sceneRange = defaultValue(
          new Extent({
            xmin: options.sceneRange.xMin,
            ymin: options.sceneRange.yMin,
            xmax: options.sceneRange.xMax,
            ymax: options.sceneRange.yMax,
            zmin: options.sceneRange.zMin,
            zmax: options.sceneRange.zMax
          }),
          undefined
        )
        /**
         * 场景中包含的图层列表
         * @member {Array} Scene.prototype.sublayers
         */
        this.sublayers = defaultValue(options.sublayers, [])
        /**
         * 场景所属的场景服务图层
         * @member {IGSSceneLayer} Scene.prototype.layer
         */
        this.layer = defaultValue(options.layer, undefined)
        /**
         * 扩展属性
         * @member {Array} Scene.prototype.extendedProps
         */
        this.extendedProps = defaultValue(options.extendedProps, undefined)
      }

      /**
       * 通过GDBP查询子图层
       * @param {String} url GDBP地址
       * @return {IGSSceneSubLayer} 子图层
       * */
      findSublayerByGDBP(url) {
        let sublayer = undefined
        for (let i = 0; i < this.sublayers.length; i++) {
          if (this.sublayers[i].url === url) {
            sublayer = this.sublayers[i]
            break
          }
        }
        return sublayer
      }

      toJSON() {
        const _sublayers = []
        for (let i = 0; i < this.sublayers.length; i++) {
          _sublayers.push(toJSON(this.sublayers[i], IGSSceneSubLayer))
        }

        return {
          sceneIndex: this.sceneIndex,
          sceneName: this.sceneName,
          sceneMode: this.sceneMode,
          sceneRange: toJSON(this.sceneRange, Extent),
          extendedProps: this.extendedProps,
          sublayers: _sublayers
        }
      }
    }

    export default Scene