package space.nstart.pcp.complan.apl

import org.springframework.beans.factory.annotation.Value
import org.springframework.stereotype.Service
import space.nstart.pcp.complan.types.GeoJson
import space.nstart.pcp.complan.types.GeoJsonItem

private val DEFAULT_GEO_JSON_LAYER_OUTPUT_DIR =
    "${System.getProperty("java.io.tmpdir")}/pcp-dynamic-plan-service/geo-layers"

@Service
class GeoJsonLayerWriter(
    @param:Value("\${complex-plan.geo-layers.enabled:false}")
    private val enabled: Boolean = false,

    @param:Value("\${complex-plan.geo-layers.output-dir:\${java.io.tmpdir}/pcp-dynamic-plan-service/geo-layers}")
    private val outputDir: String = DEFAULT_GEO_JSON_LAYER_OUTPUT_DIR
) {
    fun write(geoms: List<GeoJsonItem>, fileName: String, radToDeg: Boolean = false) {
        if (!enabled) {
            return
        }

        GeoJson.createGeoJson(geoms, fileName, outputDir, radToDeg)
    }
}
