package dev.adriankuta.flights.model.data.simple.mappers

import dev.adriankuta.flights.model.datasource.airports.entities.AirportInfoModel
import dev.adriankuta.model.data.api.entities.AirportResponse

internal fun AirportResponse.toModel(): AirportInfoModel {
    return AirportInfoModelImpl(
        code = code.orEmpty(),
        name = name.orEmpty(),
        seoName = seoName.orEmpty(),
        isBase = isBase ?: false,
        timeZone = timeZone.orEmpty(),
        cityCode = city?.code.orEmpty(),
        cityName = city?.name.orEmpty(),
        macCode = macCity?.macCode.orEmpty(),
        regionCode = region?.code.orEmpty(),
        regionName = region?.name.orEmpty(),
        countryCode = country?.code.orEmpty(),
        countryName = country?.name.orEmpty(),
        countryCurrencyCode = country?.currencyCode.orEmpty(),
        latitude = coordinates?.latitude ?: 0.0,
        longitude = coordinates?.longitude ?: 0.0,
    )
}

private data class AirportInfoModelImpl(
    override val code: String,
    override val name: String,
    override val seoName: String,
    override val isBase: Boolean,
    override val timeZone: String,
    override val cityCode: String,
    override val cityName: String,
    override val macCode: String,
    override val regionCode: String,
    override val regionName: String,
    override val countryCode: String,
    override val countryName: String,
    override val countryCurrencyCode: String,
    override val latitude: Double,
    override val longitude: Double,
) : AirportInfoModel
