package com.radiola.ui.recordings

import androidx.lifecycle.ViewModel
import com.radiola.domain.model.Recording
import com.radiola.service.RecordingPlaybackController
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.StateFlow
import javax.inject.Inject

/**
 * ViewModel экрана воспроизведения записи. Проксирует состояние и команды
 * к [RecordingPlaybackController].
 */
@HiltViewModel
class RecordingPlayerViewModel @Inject constructor(
    private val controller: RecordingPlaybackController
) : ViewModel() {

    val current: StateFlow<Recording?> = controller.current
    val isPlaying: StateFlow<Boolean> = controller.isPlaying
    val positionMs: StateFlow<Long> = controller.positionMs
    val durationMs: StateFlow<Long> = controller.durationMs

    fun play(recording: Recording) = controller.play(recording)

    fun togglePlayPause() = controller.togglePlayPause()

    fun seekTo(ms: Long) = controller.seekTo(ms)

    /** Перемотка назад на 15 секунд. */
    fun rewind15() = controller.seekBy(-15_000L)

    /** Перемотка вперёд на 15 секунд. */
    fun forward15() = controller.seekBy(15_000L)

    /** Закрыть плеер и остановить воспроизведение. */
    fun close() = controller.stop()
}
