use crate::core::cache::keys;
use crate::core::cache::mongo_cache::CacheSettings;

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

    #[test]
    fn test_cache_settings_default() {
        let settings = CacheSettings::default();
        assert!(settings.enabled);
        assert_eq!(settings.ttl_videos, 300);
        assert_eq!(settings.ttl_search, 300);
        assert_eq!(settings.ttl_hybrid_search, 600);
        assert_eq!(settings.ttl_video_meta, 3600);
    }

    #[test]
    fn test_cache_key_videos_list() {
        let key = keys::videos_list(1, 20);
        assert_eq!(key, "videos:list:page=1:limit=20");

        let key2 = keys::videos_list(2, 50);
        assert_eq!(key2, "videos:list:page=2:limit=50");
    }

    #[test]
    fn test_cache_key_video_meta() {
        let key = keys::video_meta("abc123");
        assert_eq!(key, "video:abc123");

        let uuid = "5dea6618a606e7c7";
        let key = keys::video_meta(uuid);
        assert_eq!(key, "video:5dea6618a606e7c7");
    }

    #[test]
    fn test_cache_key_search() {
        let key = keys::search("hash123");
        assert_eq!(key, "search:hash123");
    }

    #[test]
    fn test_cache_key_hybrid_search() {
        let key = keys::hybrid_search("hash123");
        assert_eq!(key, "search:hybrid:hash123");
    }

    #[test]
    fn test_cache_key_n8n_search() {
        let key = keys::n8n_search("hash123");
        assert_eq!(key, "search:n8n:hash123");
    }

    #[test]
    fn test_cache_key_health() {
        let key = keys::health();
        assert_eq!(key, "health:basic");
    }

    #[test]
    fn test_cache_categories() {
        assert_eq!(keys::CATEGORY_VIDEOS, "videos");
        assert_eq!(keys::CATEGORY_SEARCH, "search");
        assert_eq!(keys::CATEGORY_HYBRID_SEARCH, "hybrid_search");
        assert_eq!(keys::CATEGORY_VIDEO_META, "video_meta");
        assert_eq!(keys::CATEGORY_N8N_SEARCH, "n8n_search");
        assert_eq!(keys::CATEGORY_HEALTH, "health");
    }

    #[test]
    fn test_cache_key_prefixes() {
        assert_eq!(keys::KEY_PREFIX_VIDEOS_LIST, "videos:list:");
        assert_eq!(keys::KEY_PREFIX_VIDEO, "video:");
        assert_eq!(keys::KEY_PREFIX_SEARCH, "search:");
        assert_eq!(keys::KEY_PREFIX_SEARCH_HYBRID, "search:hybrid:");
        assert_eq!(keys::KEY_PREFIX_SEARCH_N8N, "search:n8n:");
        assert_eq!(keys::KEY_HEALTH, "health:basic");
    }

    #[test]
    fn test_cache_ttl_values() {
        let settings = CacheSettings::default();

        assert!(settings.ttl_videos >= 60 && settings.ttl_videos <= 600);
        assert!(settings.ttl_search >= 60 && settings.ttl_search <= 600);
        assert!(settings.ttl_hybrid_search >= 60 && settings.ttl_hybrid_search <= 3600);
        assert!(settings.ttl_video_meta >= 300 && settings.ttl_video_meta <= 7200);
    }

    #[test]
    fn test_cache_key_videos_list_prefix_format() {
        let key = keys::videos_list(1, 10);
        assert!(key.starts_with("videos:list:"));
    }

    #[test]
    fn test_cache_key_video_meta_prefix_format() {
        let key = keys::video_meta("uuid123");
        assert!(key.starts_with("video:"));
    }

    #[test]
    fn test_cache_key_search_prefix_format() {
        let key = keys::search("test");
        assert!(key.starts_with("search:"));
    }

    #[test]
    fn test_cache_key_hybrid_search_prefix_format() {
        let key = keys::hybrid_search("test");
        assert!(key.starts_with("search:hybrid:"));
    }

    #[test]
    fn test_cache_key_n8n_search_prefix_format() {
        let key = keys::n8n_search("test");
        assert!(key.starts_with("search:n8n:"));
    }
}
