package mg.dot.feufaro.viewmodel

import cafe.adriel.voyager.core.model.ScreenModel
import cafe.adriel.voyager.core.model.screenModelScope
import mg.dot.feufaro.DeepLinkHandler
import mg.dot.feufaro.FileRepository
import mg.dot.feufaro.solfa.Solfa

class SolfaScreenModel(
    val fileRepository: FileRepository,
    val solfa: Solfa
) : ScreenModel {
    init {
        DeepLinkHandler.onSongReceived = { fileContent, filePath ->
            println("QR Scan: Chemin reçu, lancement du chargement...")
            loadExternalFile(filePath)
        }
    }

    fun loadExternalFile(path: String) {
            solfa.resetShared()
            solfa.parse(path)

            println("QR Scan: Chargement terminé pour $path")
    }

    fun loadNextInPlaylist() {
        solfa.loadNextInPlaylist()
    }

    fun reload() {
        solfa.loadSolfa()
    }

    fun loadCustomFile() {
        solfa.loadFile()
    }
    fun loadFromFile(path: String) {
        solfa.parse(path)
    }
}