package id.iiyh.inatrading.feature.news.data.repository

import id.iiyh.inatrading.core.data.remote.ApiService
import id.iiyh.inatrading.feature.news.data.model.NewsArticle
import id.iiyh.inatrading.feature.news.domain.NewsRepository
import javax.inject.Inject

class NewsRepositoryImpl @Inject constructor(
    private val apiService: ApiService,
) : NewsRepository {

    override suspend fun getArticles(): Result<List<NewsArticle>> {
        return try {
            val response = apiService.getNewsArticles()
            if (response.isSuccess) {
                Result.success(response.rows)
            } else {
                Result.failure(Exception(response.responseDesc ?: "Gagal memuat berita"))
            }
        } catch (e: Exception) {
            Result.failure(e)
        }
    }
}
