package com.cr.map

/**
 * 操作系统：MAC系统
 * 创建者：王成
 * 创建日期：2023/4/13 15:50
 * 描述：地图图层管理器
 */
class LayerManager {
    /**
     * 图层分组枚举
     */
    enum class LayerGroup{
        /**
         * 常用图层
         */
        LAYER_NAME_DAILY,
        /**
         * 绘制图层
         */
        LAYER_NAME_DRAW,
        /**
         * 历史图层
         */
        LAYER_NAME_HISTORY,
        /**
         * 基础图层
         */
        LAYER_NAME_BASE,
        /**
         * 飞行图层
         */
        LAYER_NAME_AIR
    }

    // define: 2023/4/13 常量定义
    val LAYER_NAME_DAILY = "常用图层"
    val LAYER_NAME_DRAW = "绘制图层"
    val LAYER_NAME_HISTORY = "历史图层"
    val LAYER_NAME_BASE = "基础图层"
    val LAYER_NAME_AIR = "飞行图层"

    // define: 2023/4/13 图层集合
    private var mapLayers:HashMap<String,MutableList<LayerModel>> = hashMapOf()

    companion object {
        /**
         * 获取静态实例 单例
         * @return LayerManager
         */
        fun getInstance() = InstanceHelper.self
    }

    /**
     * 单例必备
     */
    object InstanceHelper{
        var self = LayerManager()
    }

    /**
     * 初始化
     */
    init {
        mapLayers?.put(LAYER_NAME_DAILY, mutableListOf())
        mapLayers?.put(LAYER_NAME_BASE, mutableListOf())
        mapLayers?.put(LAYER_NAME_HISTORY, mutableListOf())
        mapLayers?.put(LAYER_NAME_DRAW, mutableListOf())
        mapLayers?.put(LAYER_NAME_AIR, mutableListOf())
    }

    // todo: 2023/4/13 添加图层
    fun addLayer(layer:LayerModel,group:LayerGroup){
        when(group){
            LayerGroup.LAYER_NAME_BASE->
                mapLayers[LAYER_NAME_BASE]?.add(layer)
            LayerGroup.LAYER_NAME_DRAW->
                mapLayers[LAYER_NAME_DRAW]?.add(layer)
            LayerGroup.LAYER_NAME_DAILY->
                mapLayers[LAYER_NAME_DAILY]?.add(layer)
            LayerGroup.LAYER_NAME_HISTORY->
                mapLayers[LAYER_NAME_HISTORY]?.add(layer)
            LayerGroup.LAYER_NAME_AIR->
                mapLayers[LAYER_NAME_AIR]?.add(layer)
        }
    }

    /**
     * 获取图层集合
     * @return List<LayerModel>?
     */
    fun getLayers(): MutableList<LayerModel>? {
        val resList: MutableList<LayerModel> = mutableListOf()
        // TODO: 4/15/21 循环所有的数据
        for (key in mapLayers.keys) {
            val models: MutableList<LayerModel>? = mapLayers[key]
            for (i in models!!.indices) {
                val model = models[i]
                if (i == 0) {
                    model.groupName = key!!
                }
                resList.add(model)
            }
        }
        return resList
    }
}