package com.prodhack.moscow2025.presentation.screens.resumeHistory

import androidx.compose.animation.core.updateTransition
import androidx.paging.PagingData
import com.prodhack.moscow2025.domain.models.ResumeModel
import com.prodhack.moscow2025.domain.usecase.resumes.GetResumeInfoUseCase
import com.prodhack.moscow2025.domain.usecase.resumes.LoadResumeHistoryUseCase
import com.prodhack.moscow2025.presentation.utils.base.BaseViewModel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import org.koin.android.annotation.KoinViewModel
import org.koin.core.annotation.Provided

@KoinViewModel
class ResumeHistoryViewModel(
	@Provided private val resumeId: String,
	loadResumeHistoryUseCase: LoadResumeHistoryUseCase,
	private val getResumeInfoUseCase: GetResumeInfoUseCase
) : BaseViewModel() {
	val history: Flow<PagingData<ResumeModel>> = loadResumeHistoryUseCase(resumeId)

	val resumePosition = MutableUIStateFlow<String>()

	fun update() {
		getResumeInfoUseCase(resumeId = resumeId)
			.map { it -> it.map { it.position } }.collectRequest(resumePosition)
	}

	init {
		update()
	}
}
