package de.arxsilex.maptools.converter.core.pbf

import de.arxsilex.maptools.converter.core.GeoBounds
import java.nio.file.Path

fun main(arguments: Array<String>) {
    require(arguments.size == 6) {
        "Aufruf: MtciPbfWriterCli <mtci> <ausgabe.osm.pbf> <west> <south> <east> <north>"
    }
    val report = MtciPbfWriter.write(
        sourceDirectory = Path.of(arguments[0]),
        outputPath = Path.of(arguments[1]),
        bounds = GeoBounds(
            west = arguments[2].toDouble(),
            south = arguments[3].toDouble(),
            east = arguments[4].toDouble(),
            north = arguments[5].toDouble(),
        ),
        onProgress = { progress ->
            if (progress.writtenObjects % 100_000L == 0L) {
                println(
                    "MTCI-PBF phase=${progress.phase.name.lowercase()} " +
                        "objects=${progress.writtenObjects} blocks=${progress.writtenBlocks}",
                )
            }
        },
    )
    println(
        "MTCI-PBF status=completed elapsedMs=${report.elapsedMillis} bytes=${report.outputBytes} " +
            "nodes=${report.nodeCount} ways=${report.wayCount} relations=${report.relationCount} " +
            "blocks=${report.dataBlockCount}",
    )
}
