//! `ModelId` — a thin newtype over the provider's model-name string,
//! used by `App::switch_model` and (Phase D2) the `/model` picker.

/// An LLM model identifier, e.g. `claude-sonnet-4-6`. Just a string;
/// the newtype keeps `switch_model` call sites self-documenting.
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct ModelId(pub String);

impl ModelId {
    pub fn as_str(&self) -> &str {
        &self.0
    }
}

impl From<&str> for ModelId {
    fn from(s: &str) -> Self {
        Self(s.to_string())
    }
}

impl From<String> for ModelId {
    fn from(s: String) -> Self {
        Self(s)
    }
}

impl std::fmt::Display for ModelId {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(&self.0)
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn round_trips_through_str_and_string() {
        assert_eq!(
            ModelId::from("claude-sonnet-4-6").as_str(),
            "claude-sonnet-4-6"
        );
        assert_eq!(ModelId::from("x".to_string()).to_string(), "x");
    }

    #[test]
    fn equality_is_by_value() {
        assert_eq!(ModelId::from("a"), ModelId::from("a"));
        assert_ne!(ModelId::from("a"), ModelId::from("b"));
    }
}
