use serde::{Deserialize, Serialize};

use super::downbeats::DownbeatsState;

/// Response from the /api/gen/{clip_id}/aligned_lyrics/v3 endpoint
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AlignedLyricsV3 {
    /// State of the lyrics alignment: "running", "error", "complete", or "streaming"
    pub state: DownbeatsState,

    /// Error message if state is "error"
    #[serde(skip_serializing_if = "Option::is_none")]
    pub error_message: Option<String>,

    /// Whether this is the final result
    #[serde(skip_serializing_if = "Option::is_none")]
    pub r#final: Option<bool>,

    /// Word-level alignment data
    #[serde(skip_serializing_if = "Option::is_none")]
    pub alignment: Option<Vec<AlignedWord>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct AlignedWord {
    /// The word text
    pub word: String,

    /// Whether alignment was successful for this word
    pub success: bool,

    /// Start time in seconds
    pub start_s: f64,

    /// End time in seconds
    pub end_s: f64,

    /// Alignment probability/confidence
    pub p_align: f64,
}
