package com.radiola.data.remote

import com.radiola.data.remote.dto.NowPlayingItemDto
import com.radiola.data.remote.dto.StationDto
import com.radiola.domain.model.Station
import com.radiola.domain.model.Track

object ApiMapper {

    fun StationDto.toDomain(): Station {
        val cover = iconFillColored ?: bgImageMobile ?: bgImage ?: ""
        val stream = stream128 ?: stream320 ?: streamHls ?: "https://air.radiorecord.ru:805/${prefix}_128"
        return Station(
            id = id,
            name = name,
            prefix = prefix,
            streamUrl = stream,
            coverUrl = cover,
            genre = tooltip ?: "",
            tags = tags.map { it.name },
            sortOrder = sort
        )
    }

    fun NowPlayingItemDto.toDomain(): Track {
        return Track(
            artist = track.artist,
            song = track.song,
            coverUrl = track.image600 ?: track.image100,
            stationName = ""
        )
    }
}
