package com.fabledsword.minstrel.player.ui

import androidx.lifecycle.ViewModel
import com.fabledsword.minstrel.player.PlayerController
import com.fabledsword.minstrel.player.PlayerUiState
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import javax.inject.Inject

/**
 * Thin ViewModel wrapping the singleton [PlayerController] so
 * Composables can `hiltViewModel()` it via the standard Compose
 * pattern. Both MiniPlayer and NowPlayingScreen instantiate one of
 * these; the underlying PlayerController is a process-singleton, so
 * each VM exposes the same `uiState`.
 *
 * Transport methods are thin pass-throughs — the indirection earns
 * its keep by giving testing seams later (a fake PlayerController
 * stub-test for ViewModel-level logic when it grows).
 */
@HiltViewModel
class PlayerViewModel @Inject constructor(
    private val controller: PlayerController,
) : ViewModel() {

    val uiState: StateFlow<PlayerUiState> = controller.uiState
    val dropEvents: SharedFlow<String> = controller.dropEvents

    fun play() = controller.play()
    fun pause() = controller.pause()
    fun seekTo(positionMs: Long) = controller.seekTo(positionMs)
    fun skipToNext() = controller.skipToNext()
    fun skipToPrevious() = controller.skipToPrevious()
    fun seekToIndex(index: Int) = controller.seekToIndex(index)
    fun toggleShuffle() = controller.toggleShuffle()
    fun cycleRepeat() = controller.cycleRepeat()
}
