import table from './table_source.js'
import geojson from './geojson_source.js'

const sourceTypes = {
  table,
  geojson
}

class Common {
  static create(id, specification, widget) {
    if (!sourceTypes[specification.type]) {
      throw new Error(
        `Error in component "${id}": Can't resolve source type of "${specification.type}"`
      )
    }
    const source = new sourceTypes[specification.type](
      id,
      specification,
      widget
    )
    return source
  }

  static getType(name) {
    return sourceTypes[name]
  }

  static setType(name, type) {
    sourceTypes[name] = type
  }
}

export default Common
