//! `ContentFtlContributor` — registers framework-level content translations.
//!
//! This contributor provides the generic FTL strings for content pages
//! (`content.ftl`, `post.ftl`) and optional feature FTL files
//! (`features/auth.ftl`, etc.) embedded at compile time from
//! `rustelo/resources/i18n/`.
//!
//! ## Registration
//!
//! Call once at application startup, before the first request:
//!
//! ```rust,no_run
//! use rustelo_content::contributor::ContentFtlContributor;
//! use rustelo_content::register_contributor;
//!
//! register_contributor(&ContentFtlContributor).expect("content FTL registration");
//! ```
//!
//! Implementation-supplied FTL strings registered *after* this contributor
//! will shadow the framework defaults, because `FTL_REGISTRY` uses
//! `{lang}_{file_stem}` keys — implementations register per-language bundles
//! that merge at resolution time.

use std::collections::HashMap;

use rustelo_core_lib::registration::ResourceContributor;

/// Contributes embedded framework FTL strings to the global registry.
///
/// Keys follow the convention `"{language}_{file_stem}"`, e.g.:
/// - `"en_content"` → `resources/i18n/en/pages/content.ftl`
/// - `"es_post"`    → `resources/i18n/es/pages/post.ftl`
/// - `"en_auth"`    → `resources/i18n/en/features/auth.ftl` (if present)
pub struct ContentFtlContributor;

impl ResourceContributor for ContentFtlContributor {
    fn contribute_ftl(&self) -> HashMap<String, String> {
        crate::get_content_ftl()
            .into_iter()
            .map(|(k, v)| (k.to_owned(), v.to_owned()))
            .collect()
    }

    fn name(&self) -> &str {
        "rustelo_content"
    }
}

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

    #[test]
    fn contributor_has_name() {
        assert_eq!(ContentFtlContributor.name(), "rustelo_content");
    }

    #[test]
    fn contribute_ftl_returns_map() {
        let map = ContentFtlContributor.contribute_ftl();
        // Must be a HashMap — may be empty if resources/i18n doesn't exist
        // during this isolated crate build, but the type must be correct.
        let _ = map.len();
    }
}
