package ru.fincode.tsudesk.feature.news.presentation.screen

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import dagger.hilt.android.lifecycle.HiltViewModel
import ru.fincode.tsudesk.feature.news.domain.usecase.NewsInfinityFeedUseCase
import javax.inject.Inject

@HiltViewModel
class NewsViewModel @Inject constructor(
    private val feed: NewsInfinityFeedUseCase
) : ViewModel() {

    val state = feed.state

    init {
        feed.attach(viewModelScope)
        feed.refresh()
    }

    fun onScrolledToEnd() {
        feed.loadNext()
    }

    fun onRetry() {
        feed.loadNext()
    }
}