use std::path::Path;

/// The source languages Glyph parses today. Labels are user-facing coverage facts.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum SourceLanguage {
    Rust,
    Python,
    TypeScript,
    Tsx,
}

impl SourceLanguage {
    pub(crate) fn label(self) -> &'static str {
        match self {
            SourceLanguage::Rust => "rust",
            SourceLanguage::Python => "python",
            SourceLanguage::TypeScript => "typescript",
            SourceLanguage::Tsx => "tsx",
        }
    }
}

pub(crate) fn language_for_path(path: &Path) -> Option<SourceLanguage> {
    match path.extension().and_then(|x| x.to_str()) {
        Some("rs") => Some(SourceLanguage::Rust),
        Some("py") => Some(SourceLanguage::Python),
        Some("ts") => Some(SourceLanguage::TypeScript),
        Some("tsx") => Some(SourceLanguage::Tsx),
        _ => None,
    }
}
