package pl.firmatpp.kierowca.domain

import kotlin.math.roundToInt
import pl.firmatpp.kierowca.data.model.DriverRouteDto

data class RouteCardDisplay(
    val id: String,
    val origin: String,
    val destination: String,
    val contractLabel: String,
    val time: String,
    val status: String,
    val distanceLabel: String,
)

object RouteDisplayMapper {
    fun toCard(route: DriverRouteDto): RouteCardDisplay {
        val contract = route.contractCode
            ?.takeIf { it.isNotBlank() }
            ?: route.contractName?.takeIf { it.isNotBlank() }
            ?: route.contractorName

        val distance = route.distanceKm
            ?.takeIf { it > 0.0 }
            ?.roundToInt()
            ?.let { "$it km" }
            ?: ""

        return RouteCardDisplay(
            id = route.id,
            origin = route.originName.ifBlank { "Start" },
            destination = route.destinationName.ifBlank { "Cel" },
            contractLabel = contract,
            time = route.startsAt.ifBlank { "--:--" },
            status = route.status,
            distanceLabel = distance,
        )
    }
}
