package content

import audio.AudioFileInfo

/**
 * Class to manage loaded content in the application.
 * This class provides methods to retrieve and add soundbank data based on specific criteria.
 */
@Suppress("unused")
class ContentCache {
    val contentList = ArrayList<SoundbankData>()

    /**
     * Get the specified SoundbankData from tag, category, language, and voiceType.
     * @return SoundbankData if found, null otherwise.
     */
    fun Get(tag: String, category: Category, language: Language, voiceType: VoiceType): SoundbankData? {

        return contentList.find { it ->
            it.TAG == tag &&
            it.Category == category &&
            it.Language == language &&
            it.VoiceType == voiceType &&
            it.audio.isValid()
        }
    }

    /**
     * Adds a new soundbank to the content list if it does not already exist.
     *
     * @param tag The unique identifier for the soundbank.
     * @param category The category of the soundbank.
     * @param language The language of the soundbank.
     * @param voiceType The voice type of the soundbank.
     * @param audio The audio file information for the soundbank.
     * @return True if the soundbank was added, false if it already exists.
     */
    fun Add(tag: String, category: Category, language: Language, voiceType: VoiceType, audio: AudioFileInfo): Boolean {
        val existing = Get(tag, category, language, voiceType)
        if (existing!=null) return false
        contentList.add(SoundbankData(tag, category, language, voiceType, audio))
        return true
    }
}