package ru.fincode.tsudesk.feature.news.data.remote.datasource

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import ru.fincode.tsudesk.core.network.apiCall
import ru.fincode.tsudesk.core.network.model.NetworkResult
import ru.fincode.tsudesk.core.network.model.map
import ru.fincode.tsudesk.feature.news.data.remote.NewsApi
import javax.inject.Inject

class NewsRemoteDataSource @Inject constructor(
    private val api: NewsApi
) {
    suspend fun loadArchivePageHtml(page: Int): NetworkResult<String> =
        withContext(Dispatchers.IO) {
            apiCall { api.getNewsArchive(page = page) }
                .map { body, _ -> body.string() }
        }
}