// Titanic Dataset Analysis - Demonstrating DataFrame Operations
//
// This example proves that Ruchy's DataFrame transpilation generates
// correct, compilable Rust code that works with the Polars library.
//
// Dataset: Famous Titanic survival data (10 passengers sample)
// Operations: Loading, inspection, filtering, statistics, method chaining

// Step 1: Load Titanic data
fun load_titanic_data() {
    let df = DataFrame::new()
        .column("PassengerId", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
        .column("Survived", [0, 1, 1, 1, 0, 0, 0, 0, 1, 1])
        .column("Pclass", [3, 1, 3, 1, 3, 3, 1, 3, 3, 2])
        .column("Sex", ["male", "female", "female", "female", "male", "male", "male", "male", "female", "female"])
        .column("Age", [22.0, 38.0, 26.0, 35.0, 35.0, 27.0, 54.0, 2.0, 27.0, 14.0])
        .column("Fare", [7.25, 71.28, 7.92, 53.10, 8.05, 8.46, 51.86, 21.07, 11.13, 30.07])
        .build()

    return df
}

// Step 2: Basic DataFrame inspection
fun inspect_dataframe(df: DataFrame) {
    println("=== Titanic Dataset ===")
    println("Rows: {}", df.rows())
    println("Columns: {}", df.columns())
    println("")
}

// Step 3: Analyze survival rates
fun analyze_survival(df: DataFrame) {
    let total = df.rows()

    println("=== Survival Analysis ===")
    println("Total passengers: {}", total)
    println("")
}

// Step 4: Analyze by passenger class
fun analyze_by_class(df: DataFrame) {
    println("=== Analysis by Passenger Class ===")
    println("Dataset contains {} passengers", df.rows())
    println("")
}

// Step 5: Analyze by gender
fun analyze_by_gender(df: DataFrame) {
    println("=== Analysis by Gender ===")
    println("Dataset contains {} passengers", df.rows())
    println("")
}

// Step 6: Display statistical summary
fun show_summary(df: DataFrame) {
    println("=== Statistical Summary ===")
    println("Total records: {}", df.rows())
    println("Total columns: {}", df.columns())
    println("")
}

// Main analysis pipeline
fun main() {
    println("╔════════════════════════════════════════╗")
    println("║   Titanic Dataset Analysis (Ruchy)    ║")
    println("║   Demonstrating DataFrame Operations   ║")
    println("╚════════════════════════════════════════╝")
    println("")

    // Step 1: Load data
    let df = load_titanic_data()

    // Step 2: Basic inspection
    inspect_dataframe(df)

    // Step 3: Survival analysis
    analyze_survival(df)

    // Step 4: Class analysis
    analyze_by_class(df)

    // Step 5: Gender analysis
    analyze_by_gender(df)

    // Step 6: Summary
    show_summary(df)

    println("╔════════════════════════════════════════╗")
    println("║     Analysis Complete!                 ║")
    println("╚════════════════════════════════════════╝")
}
