package net.sergeych.toread

import kotlinx.coroutines.flow.StateFlow

data class ReadAloudSentence(
    val index: Int,
    val itemIndex: Int,
    val start: Int,
    val endExclusive: Int,
    val text: String,
    val spokenText: String = text,
    val pauseBeforeMillis: Long = 0,
    val pauseAfterMillis: Long = 0,
)

data class ReadAloudState(
    val active: Boolean = false,
    val playing: Boolean = false,
    val sentenceIndex: Int? = null,
)

data class ReadAloudEngineOption(
    val id: String,
    val label: String,
)

data class ReadAloudVoiceOption(
    val id: String,
    val label: String,
    val localeTag: String,
    val networkRequired: Boolean,
)

data class ReadAloudTextReplacement(
    val from: String,
    val to: String,
    val caseSensitive: Boolean = false,
)

data class ReadAloudSettingsState(
    val engines: List<ReadAloudEngineOption> = emptyList(),
    val selectedEngineId: String? = null,
    val voices: List<ReadAloudVoiceOption> = emptyList(),
    val selectedVoiceId: String? = null,
    val textReplacements: List<ReadAloudTextReplacement> = emptyList(),
    val loading: Boolean = false,
    val message: String? = null,
)

expect object ReadAloudPlatform {
    val isSupported: Boolean
    val state: StateFlow<ReadAloudState>
    val settingsState: StateFlow<ReadAloudSettingsState>

    fun prepare(fileId: String, bookTitle: String, sentences: List<ReadAloudSentence>, startIndex: Int)
    fun play()
    fun stop()
    fun skip(delta: Int)
    fun refreshSettings()
    fun selectEngine(engineId: String?)
    fun selectVoice(voiceId: String?)
}
