package de.arxsilex.maptools.converter.desktop

import de.arxsilex.maptools.converter.core.InputFileInfo
import de.arxsilex.maptools.converter.core.InputFormat

/** Separates renderable map sources from their independently mergeable POI databases. */
internal data class InputSourceSet(
    val mapSources: List<InputFileInfo>,
    val poiSources: List<InputFileInfo>,
    val elevationSources: List<InputFileInfo>,
) {
    val selectionSources: List<InputFileInfo>
        get() = mapSources + poiSources + elevationSources

    val previewSources: List<InputFileInfo>
        get() = mapSources.ifEmpty { poiSources }

    val isPoiOnly: Boolean
        get() = mapSources.isEmpty() && poiSources.isNotEmpty() && elevationSources.isEmpty()

    val isElevationOnly: Boolean
        get() = mapSources.isEmpty() && poiSources.isEmpty() && elevationSources.isNotEmpty()

    val hasPoiCompanion: Boolean
        get() = mapSources.isNotEmpty() && poiSources.isNotEmpty()

    val hasMapData: Boolean
        get() = mapSources.isNotEmpty()

    val hasPoiData: Boolean
        get() = poiSources.isNotEmpty() || mapSources.isNotEmpty()

    val hasElevationData: Boolean
        get() = elevationSources.isNotEmpty()
}

internal fun List<InputFileInfo>.toInputSourceSet(): InputSourceSet {
    return InputSourceSet(
        mapSources = filter { it.format.isMapData },
        poiSources = filter { it.format == InputFormat.MAPSFORGE_POI },
        elevationSources = filter { it.format.isElevationData },
    )
}
