import ConvertSymbolUtil from './ConvertSymbolUtil'
// 转换渲染器
class ConvertRendererUtil {
  /**
   * @description 转换为cesium需要的渲染器样式,此处暂时转换样式处理，最终期望render能直接转换cesium样式
   * @public
   * @param {*} renderer
   * @return {*}
   */
  static rendererToFeatureRenderer(renderer) {
    let cesiumRenderer = {
      type: 'simple',
      symbol: ConvertSymbolUtil.convertSymboltoFeatureStyle()
    }
    if (!renderer) return cesiumRenderer
    switch (renderer.type) {
      case 'simple': {
        cesiumRenderer = {
          type: 'simple',
          symbol: ConvertSymbolUtil.convertSymboltoFeatureStyle(renderer.symbol)
        }
        break
      }
      case 'unique-value': {
        const defaultSymbol = ConvertSymbolUtil.convertSymboltoFeatureStyle(
          renderer.defaultSymbol
        )
        cesiumRenderer = {
          type: 'unique-value',
          defaultSymbol,
          field: renderer.field,
          uniqueValueInfos: renderer.uniqueValueInfos.map((v) => {
            return {
              value: v.value,
              symbol: ConvertSymbolUtil.convertSymboltoFeatureStyle(
                v.symbol,
                defaultSymbol
              )
            }
          })
        }
        break
      }
      case 'class-breaks': {
        const defaultSymbol = ConvertSymbolUtil.convertSymboltoFeatureStyle(
          renderer.defaultSymbol
        )
        cesiumRenderer = {
          type: 'class-breaks',
          field: renderer.field,
          defaultSymbol: ConvertSymbolUtil.convertSymboltoFeatureStyle(
            renderer.defaultSymbol
          ),
          classBreakInfos: renderer.classBreakInfos.map((v) => {
            return {
              maxValue: v.maxValue,
              minValue: v.minValue,
              symbol: ConvertSymbolUtil.convertSymboltoFeatureStyle(
                v.symbol,
                defaultSymbol
              )
            }
          })
        }
        break
      }
      default: {
        cesiumRenderer = {
          type: 'simple',
          symbol: ConvertSymbolUtil.convertSymboltoFeatureStyle(renderer.symbol)
        }
        break
      }
    }
    return cesiumRenderer
  }
}
export default ConvertRendererUtil
