#![allow(dead_code)]
#![allow(unused_imports)]
//! Ingredient Mapper Service
//!
//! Maps EU drug names to US drug names for interaction checking
//!
//! Example:
//! - Paracetamol (EU) → Acetaminophen (US)

use std::collections::HashMap;

#[derive(Clone)]
pub struct IngredientMapper {
    mappings: HashMap<String, String>,
}

impl IngredientMapper {
    pub fn new() -> Self {
        let mut mappings = HashMap::new();

        // EU to US drug name mappings
        mappings.insert("paracetamol".to_string(), "acetaminophen".to_string());
        mappings.insert("paracetamolum".to_string(), "acetaminophen".to_string());
        mappings.insert("acetylsalicylic acid".to_string(), "aspirin".to_string());

        // Antibiotics
        mappings.insert("amoxicilline".to_string(), "amoxicillin".to_string());
        mappings.insert("amoxicillinum".to_string(), "amoxicillin".to_string());

        // These are the same in both
        mappings.insert("ibuprofen".to_string(), "ibuprofen".to_string());
        mappings.insert("metformin".to_string(), "metformin".to_string());
        mappings.insert("lisinopril".to_string(), "lisinopril".to_string());
        mappings.insert("atorvastatin".to_string(), "atorvastatin".to_string());
        mappings.insert("simvastatin".to_string(), "simvastatin".to_string());
        mappings.insert("omeprazole".to_string(), "omeprazole".to_string());

        Self { mappings }
    }

    /// Map EU drug name to US drug name
    pub fn map_to_us(&self, eu_name: &str) -> String {
        let normalized = eu_name.to_lowercase().trim().to_string();

        self.mappings
            .get(&normalized)
            .unwrap_or(&eu_name.to_string())
            .clone()
    }

    /// Map multiple EU drug names to US names
    pub fn map_many_to_us(&self, eu_names: &[String]) -> Vec<String> {
        eu_names.iter().map(|name| self.map_to_us(name)).collect()
    }

    /// Add a custom mapping
    pub fn add_mapping(&mut self, eu_name: String, us_name: String) {
        self.mappings.insert(eu_name.to_lowercase(), us_name);
    }
}

impl Default for IngredientMapper {
    fn default() -> Self {
        Self::new()
    }
}

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

    #[test]
    fn test_paracetamol_mapping() {
        let mapper = IngredientMapper::new();
        assert_eq!(mapper.map_to_us("paracetamol"), "acetaminophen");
    }

    #[test]
    fn test_same_name() {
        let mapper = IngredientMapper::new();
        assert_eq!(mapper.map_to_us("ibuprofen"), "ibuprofen");
    }

    #[test]
    fn test_case_insensitive() {
        let mapper = IngredientMapper::new();
        assert_eq!(mapper.map_to_us("PARAcetamol"), "acetaminophen");
    }
}
