use super::*;

#[test]
fn all_twentyfive_builtins_registered() {
    let mut registry = ProfileRegistry::new();
    register_builtins(&mut registry).unwrap();
    assert_eq!(registry.list().len(), 25);
}

#[test]
fn trending_has_max_per_creator_1() {
    let mut registry = ProfileRegistry::new();
    register_builtins(&mut registry).unwrap();
    let trending = registry.get("trending").unwrap();
    assert_eq!(trending.diversity.max_per_creator, Some(1));
}

#[test]
fn shuffle_has_exploration_0_5() {
    let mut registry = ProfileRegistry::new();
    register_builtins(&mut registry).unwrap();
    let shuffle = registry.get("shuffle").unwrap();
    assert_eq!(shuffle.exploration, 0.5);
}

#[test]
fn hot_gravity_is_1_8() {
    let mut registry = ProfileRegistry::new();
    register_builtins(&mut registry).unwrap();
    let hot = registry.get("hot").unwrap();
    match &hot.sort {
        Some(Sort::Hot { gravity }) => assert_eq!(*gravity, 1.8),
        other => panic!("expected Sort::Hot, got {other:?}"),
    }
}

#[test]
fn for_you_has_exploration() {
    let mut registry = ProfileRegistry::new();
    register_builtins(&mut registry).unwrap();
    let p = registry.get("for_you").unwrap();
    assert!(p.exploration > 0.0);
    assert!(p.diversity.max_per_creator.is_some());
    assert!(p.diversity.format_mix_max_fraction.is_some());
}

#[test]
fn following_uses_relationship_strategy() {
    let mut registry = ProfileRegistry::new();
    register_builtins(&mut registry).unwrap();
    let p = registry.get("following").unwrap();
    assert!(
        matches!(p.candidate_strategy, CandidateStrategy::Relationship),
        "following should use Relationship strategy"
    );
}

#[test]
fn notification_max_per_creator_1() {
    let mut registry = ProfileRegistry::new();
    register_builtins(&mut registry).unwrap();
    let p = registry.get("notification").unwrap();
    assert_eq!(p.diversity.max_per_creator, Some(1));
}

#[test]
fn related_profile_exists() {
    let mut registry = ProfileRegistry::new();
    register_builtins(&mut registry).unwrap();
    assert!(registry.get("related").is_ok());
}

#[test]
fn cohort_trending_has_same_boosts_as_trending() {
    let mut registry = ProfileRegistry::new();
    register_builtins(&mut registry).unwrap();
    let ct = registry.get("cohort_trending").unwrap();
    let t = registry.get("trending").unwrap();

    // Same sort mode.
    assert!(
        matches!(ct.sort, Some(Sort::Trending)),
        "cohort_trending should use Trending sort"
    );
    // Same number of boosts.
    assert_eq!(
        ct.boosts.len(),
        t.boosts.len(),
        "cohort_trending should have same number of boosts as trending"
    );
    // Same diversity constraint.
    assert_eq!(ct.diversity.max_per_creator, Some(1));
}
