package mg.dot.feufaro.solfa

class PNotes (var note: String, var noteSplit: MutableList<String> = mutableListOf(), private var markers: MutableList<String> = mutableListOf()) {
        fun addMarker(newMarker: String) {
        markers.add(newMarker)
    }
    fun hasMarker(marker: String): Boolean {
        return markers.contains(marker)
    }
    fun toNote(): Note {
        val validSplits = noteSplit.filter { it.isNotBlank() }

        val finalNoteStr = if (validSplits.isNotEmpty()) {
            val formattedSplits = if (validSplits.size > 1) {
                validSplits.joinToString("|")
            } else {
                validSplits.joinToString("")
            }
            "$note>{$formattedSplits}"
        } else {
            note
        }

        val newNote = Note(finalNoteStr)
        newNote.setMarkers(markers)
        return newNote
    }
    // appendNote is used in POneVoiceNote.appendLastNote()
    fun appendNote(noteSuffix: Char) {
        note += noteSuffix
    }
    fun addSplitNote(splitNote: String) {
        noteSplit.add(splitNote)
    }
    fun appendSplitNote(suffix: Char) {
        if (noteSplit.isNotEmpty()) {
            noteSplit[noteSplit.lastIndex] += suffix
        }
    }
}