{{!-- Template for Optimized Roman script converters using RomanScriptProcessor with FxHashMap --}}

// Pre-computed static mappings with FxHashMap for performance
static {{uppercase script_name}}_TO_ISO_MAP: Lazy<FxHashMap<&'static str, &'static str>> = Lazy::new(|| {
    let mut map = FxHashMap::default();
    
{{#each mappings}}
    map.insert("{{escape @key}}", "{{escape this}}");
{{/each}}
    
    map
});

static ISO_TO_{{uppercase script_name}}_MAP: Lazy<FxHashMap<&'static str, &'static str>> = Lazy::new(|| {
    let mut map = FxHashMap::default();
    
    // Build reverse mapping with explicit precedence for multi-character sequences
    // Handle longer sequences first to avoid conflicts
{{#each reverse_priority_mappings}}
    map.insert("{{escape this}}", "{{escape @key}}");
{{/each}}
    
    // Then build the rest avoiding conflicts
    for (&{{lowercase script_name}}, &iso) in {{uppercase script_name}}_TO_ISO_MAP.iter() {
        if !map.contains_key(iso) {
            map.insert(iso, {{lowercase script_name}});
        }
    }
    
    map
});

/// Optimized {{script_name}} converter with FxHashMap for performance
pub struct {{struct_name}} {
    {{lowercase script_name}}_to_iso_map: &'static FxHashMap<&'static str, &'static str>,
    iso_to_{{lowercase script_name}}_map: &'static FxHashMap<&'static str, &'static str>,
}

impl {{struct_name}} {
    pub fn new() -> Self {
        Self {
            {{lowercase script_name}}_to_iso_map: &{{uppercase script_name}}_TO_ISO_MAP,
            iso_to_{{lowercase script_name}}_map: &ISO_TO_{{uppercase script_name}}_MAP,
        }
    }
    
    /// Convert {{script_name}} to ISO-15919 using optimized processor
    pub fn {{lowercase script_name}}_to_iso(&self, input: &str) -> Result<String, ConverterError> {
        RomanScriptProcessor::process_with_fx_hashmap(input, self.{{lowercase script_name}}_to_iso_map)
    }
    
    /// Convert ISO-15919 to {{script_name}} using optimized processor
    pub fn iso_to_{{lowercase script_name}}(&self, input: &str) -> Result<String, ConverterError> {
        RomanScriptProcessor::process_with_fx_hashmap(input, self.iso_to_{{lowercase script_name}}_map)
    }
    
    {{#each aliases}}
    /// Script-specific alias method
    pub fn {{this.[0]}}(&self, input: &str) -> Result<String, ConverterError> {
        self.{{this.[1]}}(input)
    }
    {{/each}}
}

impl ScriptConverter for {{struct_name}} {
    fn to_hub(&self, script: &str, input: &str) -> Result<HubInput, ConverterError> {
        if script != "{{script_name}}" {
            return Err(ConverterError::InvalidInput {
                script: script.to_string(),
                message: "{{struct_name}} converter only supports '{{script_name}}' script".to_string(),
            });
        }

        let iso_text = self.{{lowercase script_name}}_to_iso(input)?;
        Ok(HubInput::Iso(iso_text))
    }

    fn from_hub(&self, script: &str, hub_input: &HubInput) -> Result<String, ConverterError> {
        if script != "{{script_name}}" {
            return Err(ConverterError::InvalidInput {
                script: script.to_string(),
                message: "{{struct_name}} converter only supports '{{script_name}}' script".to_string(),
            });
        }

        match hub_input {
            HubInput::Iso(iso_text) => self.iso_to_{{lowercase script_name}}(iso_text),
            HubInput::Devanagari(_) => Err(ConverterError::ConversionFailed {
                script: script.to_string(),
                reason: "{{struct_name}} converter expects ISO input, got Devanagari".to_string(),
            }),
        }
    }

    fn supported_scripts(&self) -> Vec<&'static str> {
        vec!["{{script_name}}"]
    }

    fn script_has_implicit_a(&self, _script: &str) -> bool {
        {{has_implicit_a}}
    }
}

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