package com.openclaw.alfred.voice

import android.util.Log
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * Helper to manage ElevenLabs voices.
 * Voice list is hardcoded from SAG CLI output (since Android can't execute Linux commands).
 */
object VoiceHelper {
    
    private const val TAG = "VoiceHelper"
    
    data class Voice(
        val id: String,
        val name: String,
        val category: String
    )
    
    /**
     * Hardcoded voice list from SAG CLI.
     * Updated: 2025-02-08
     */
    private val VOICES = listOf(
        Voice("vBKc2FfBKJfcZNyEt1n6", "Finn - Youthful, Eager and Energetic", "professional"),
        Voice("EXAVITQu4vr4xnSDxMaL", "Sarah - Mature, Reassuring, Confident", "premade"),
        Voice("CwhRBWXzGAHq8TQ4Fs17", "Roger - Laid-Back, Casual, Resonant", "premade"),
        Voice("FGY2WhTYpPnrIDTdsKH5", "Laura - Enthusiast, Quirky Attitude", "premade"),
        Voice("IKne3meq5aSn9XLyUdCD", "Charlie - Deep, Confident, Energetic", "premade"),
        Voice("JBFqnCBsd6RMkjVDRZzb", "George - Warm, Captivating Storyteller", "premade"),
        Voice("N2lVS1w4EtoT3dr4eOWO", "Callum - Husky Trickster", "premade"),
        Voice("SAz9YHcvj6GT2YYXdXww", "River - Relaxed, Neutral, Informative", "premade"),
        Voice("SOYHLrjzK2X1ezoPC6cr", "Harry - Fierce Warrior", "premade"),
        Voice("TX3LPaxmHKxFdv7VOQHJ", "Liam - Energetic, Social Media Creator", "premade"),
        Voice("Xb7hH8MSUJpSbSDYk0k2", "Alice - Clear, Engaging Educator", "premade"),
        Voice("XrExE9yKIg1WjnnlVkGX", "Matilda - Knowledgable, Professional", "premade"),
        Voice("bIHbv24MWmeRgasZH58o", "Will - Relaxed Optimist", "premade"),
        Voice("cgSgspJ2msm6clMCkdW9", "Jessica - Playful, Bright, Warm", "premade"),
        Voice("cjVigY5qzO86Huf0OWal", "Eric - Smooth, Trustworthy", "premade"),
        Voice("hpp4J3VqNfWAUOO0d1Us", "Bella - Professional, Bright, Warm", "premade"),
        Voice("iP95p4xoKVk53GoZ742B", "Chris - Charming, Down-to-Earth", "premade"),
        Voice("nPczCjzI2devNBz1zQrb", "Brian - Deep, Resonant and Comforting", "premade"),
        Voice("onwK4e9ZLuTAKqWW03F9", "Daniel - Steady Broadcaster", "premade"),
        Voice("pFZP5JQG7iQjIQuC4Bku", "Lily - Velvety Actress", "premade"),
        Voice("pNInz6obpgDQGcFmaJgB", "Adam - Dominant, Firm", "premade"),
        Voice("pqHfZKP75CvOlQylNhV4", "Bill - Wise, Mature, Balanced", "premade"),
        Voice("5Xx8kcjjamcaKohQT5wv", "Joe - Conversational Storyteller", "professional"),
        Voice("5l5f8iK3YPeGga21rQIX", "Adeline", "professional"),
        Voice("7p1Ofvcwsv7UBPoFNcpI", "Julian - deep rich mature British voice", "professional"),
        Voice("BZgkqPqms7Kj9ulSkVzn", "Eve", "professional"),
        Voice("DMyrgzQFny3JI1Y1paM5", "Donovan", "professional"),
        Voice("Dslrhjl3ZpzrctukrQSN", "Hey Its Brad - Clear Narrator for Documentary", "professional"),
        Voice("IsEXLHzSvLH9UMB6SLHj", "Mellow Matt", "professional"),
        Voice("M7ya1YbaeFaPXljg9BpK", "Hannah the natural Australian Voice", "professional"),
        Voice("NNl6r8mD7vthiJatiJt1", "Bradford", "professional"),
        Voice("ROMJ9yK1NAMuu1ggrjDW", "Relaxing Rachel - Calm & Soothing", "professional"),
        Voice("Sq93GQT4X1lKDXsQcixO", "Felix - Warm, positive & contemporary RP", "professional"),
        Voice("UgBBYS2sOqTuMpoF3BR0", "Mark - Natural Conversations", "professional"),
        Voice("WdZjiN0nNcik2LBjOHiv", "David - Wise & Knowledgeable", "professional"),
        Voice("c6SfcYrb2t09NHXiT80T", "Jarnathan - Confident and Versatile", "professional"),
        Voice("gfRt6Z3Z8aTbpLfexQ7N", "Boyd", "professional"),
        Voice("giAoKpl5weRTCJK7uB9b", "Owen - Engaging British Storyteller", "professional"),
        Voice("goT3UYdM9bhm0n2lmKQx", "Edward - British, Dark, Seductive, Low", "professional"),
        Voice("jbEI5QkrMSKWeDlP27MV", "Ryan", "professional"),
        Voice("pVnrL6sighQX7hVz89cp", "Soothing Narrator", "professional"),
        Voice("scOwDtmlUjD3prqpp97I", "Sam - Support Agent & Audiobooks", "professional"),
        Voice("y1adqrqs4jNaANXsIZnD", "David Boles", "professional"),
        Voice("yr43K8H5LoTp6S1QFSGg", "Matt", "professional")
    )
    
    /**
     * Get available voices (returns hardcoded list).
     */
    suspend fun fetchVoices(): List<Voice> = withContext(Dispatchers.IO) {
        Log.d(TAG, "Returning ${VOICES.size} hardcoded voices")
        VOICES
    }
    
    /**
     * Get voice name by ID (from cached list).
     */
    fun getVoiceName(voices: List<Voice>, voiceId: String): String {
        return voices.find { it.id == voiceId }?.name ?: voiceId
    }
}
