//! Tests for fluent content models

use rustelo_core_lib::fluent::{
    ContentMetadata, ContentQuery, ContentState, ContentTemplate, ContentType, PageContent,
};

#[test]
fn test_page_content_creation() {
    let content = PageContent::new(
        "test-page".to_string(),
        "Test Page".to_string(),
        "test-page".to_string(),
        ContentType::Page,
        "# Test Content".to_string(),
        "page-container".to_string(),
        None,
    );

    assert_eq!(content.slug, "test-page");
    assert_eq!(content.title, "Test Page");
    assert_eq!(content.content_type, ContentType::Page);
    assert_eq!(content.state, ContentState::Draft);
    assert!(!content.require_login);
}

#[test]
fn test_content_accessibility() {
    let mut content = PageContent::new(
        "test".to_string(),
        "Test".to_string(),
        "test".to_string(),
        ContentType::Page,
        "Content".to_string(),
        "container".to_string(),
        None,
    );

    // Draft content should not be accessible
    assert!(!content.is_accessible(false));
    assert!(!content.is_accessible(true));

    // Published content should be accessible
    content.set_published();
    assert!(content.is_accessible(false));
    assert!(content.is_accessible(true));

    // Login required content
    content.require_login = true;
    assert!(!content.is_accessible(false));
    assert!(content.is_accessible(true));
}

#[test]
fn test_content_query_builder() {
    let query = ContentQuery::new()
        .with_content_type(ContentType::Blog)
        .with_state(ContentState::Published)
        .with_pagination(10, 0)
        .public_only();

    assert_eq!(query.content_type, Some(ContentType::Blog));
    assert_eq!(query.state, Some(ContentState::Published));
    assert_eq!(query.limit, Some(10));
    assert_eq!(query.offset, Some(0));
    assert_eq!(query.require_login, Some(false));
}

#[test]
fn test_content_metadata() {
    let mut metadata = ContentMetadata::new("Test Title".to_string())
        .with_description("Test description".to_string())
        .with_author("Test Author".to_string());

    metadata
        .estimate_reading_time("This is a test content with some words to estimate reading time.");

    assert_eq!(metadata.title, "Test Title");
    assert_eq!(metadata.description, Some("Test description".to_string()));
    assert_eq!(metadata.author, Some("Test Author".to_string()));
    assert!(metadata.reading_time.is_some());
    assert!(metadata.word_count.is_some());
}

#[test]
fn test_content_templates() {
    let blog_template = ContentTemplate::blog_template();
    assert_eq!(blog_template.name, "Blog Post");
    assert_eq!(blog_template.default_content_type, ContentType::Blog);
    assert!(blog_template.supports_comments);
    assert!(blog_template.supports_tags);

    let page_template = ContentTemplate::page_template();
    assert_eq!(page_template.name, "Static Page");
    assert_eq!(page_template.default_content_type, ContentType::Page);
    assert!(!page_template.supports_comments);
    assert!(!page_template.supports_tags);
}

#[test]
fn test_content_type_conversion() {
    let content_type = ContentType::from("blog".to_string());
    assert_eq!(content_type, ContentType::Blog);

    let custom_type = ContentType::from("custom_type".to_string());
    assert_eq!(custom_type, ContentType::Custom("custom_type".to_string()));
}
