//! ResponseData From Trait 示例
//!
//! 展示 ResponseData 的 From<T> 和 From<Vec<T>> 转换

use anycms_core::ResponseData;
use serde::Serialize;

#[derive(Debug, Serialize)]
struct User {
    id: u32,
    name: String,
}

fn main() {
    println!("=== ResponseData From Trait Demo ===\n");

    // 1. From<T> — 单值自动转换
    println!("1. From<T> (single value):");
    let user = User {
        id: 1,
        name: "Alice".to_string(),
    };
    let data: ResponseData<User> = user.into();
    assert!(data.is_single());
    println!("   is_single: {}", data.is_single());
    println!("   value: {:?}\n", data.as_single());

    // 2. From<Vec<T>> — 列表自动转换
    println!("2. From<Vec<T>> (list):");
    let users = vec![
        User {
            id: 1,
            name: "Alice".to_string(),
        },
        User {
            id: 2,
            name: "Bob".to_string(),
        },
    ];
    let data: ResponseData<User> = users.into();
    assert!(data.is_multiple());
    println!("   is_multiple: {}", data.is_multiple());
    println!("   count: {}\n", data.as_multiple().unwrap().len());

    // 3. 用于构造 Option<ResponseData<T>>
    println!("3. Used with Option<ResponseData<T>>:");
    let user = User {
        id: 3,
        name: "Charlie".to_string(),
    };
    let data: Option<ResponseData<User>> = Some(user.into());
    println!("   Some(single): {}\n", data.unwrap().is_single());
}
