// tests/integration.rs

use axioma::prelude::*;

#[test]
fn test_kotowari_lossy_engine_k8s_manifest() {
    // Parsing a deeply nested Kubernetes Pod manifest in O(1)
    let engine = kotowari!({
        "apiVersion": "v1",
        "kind": "Pod",
        "metadata": {
            "name": "nginx",
            "labels": {
                "app": "web",
                "tier": "frontend"
            }
        },
        "spec": {
            "containers": [
                {
                    "name": "nginx",
                    "image": "nginx:1.14.2",
                    "ports": [
                        { "containerPort": 80 }
                    ]
                }
            ]
        }
    });

    // 2D Space Mapping (r: depth, c: sibling offset)
    assert_eq!(engine(0, 0), AxiValue::Str("apiVersion"));
    assert_eq!(engine(1, 0), AxiValue::Str("v1"));

    assert_eq!(engine(0, 2), AxiValue::Str("metadata"));
    assert_eq!(engine(2, 2), AxiValue::Str("nginx"));
    assert_eq!(engine(3, 4), AxiValue::Str("frontend"));

    assert_eq!(engine(0, 5), AxiValue::Str("spec"));
    assert_eq!(engine(3, 6), AxiValue::Str("nginx:1.14.2"));
    assert_eq!(engine(4, 7), AxiValue::Num("80"));
}

#[test]
fn test_axioma_lossless_engine_topology_skip() {
    // Proving O(1) subtree skipping using next_c
    let engine = axioma!({
        "huge_payload": {
            "data": [ 1, 2, 3, 4, 5, { "nested": "deep" } ],
            "meta": "ignore"
        },
        "target": "found"
    });

    // Root key "huge_payload" is at (0, 0)
    let (kind, next_c, val) = engine(0, 0);
    assert_eq!(kind, 1); // 1 = Object Key
    assert_eq!(val, AxiValue::Str("huge_payload"));

    // Skip the entire huge_payload object using next_c
    let (_, _, target_val) = engine(0, next_c);
    assert_eq!(target_val, AxiValue::Str("target"));
}

#[test]
fn test_imprint_drive_engine_deep_search() {
    // imprint! compiles into a static Data Segment accessed via 2D coordinates
    let engine = imprint!({
        "sys": { "id": "1", "type": "Asset" },
        "fields": {
            "title": "Hero Image",
            "file": {
                "url": "//cdn.example.com/img.jpg",
                "details": {
                    "size": 1024,
                    "image": { "width": 800, "height": 600 }
                }
            }
        }
    });

    // 2D Space Mapping (r: depth, c: sibling offset)
    // c=0: sys (r=0) -> id (r=1) -> 1 (r=2)
    // c=1:              type (r=1) -> Asset (r=2)
    // c=2: fields (r=0) -> title (r=1) -> Hero Image (r=2)
    // c=3:                 file (r=1) -> url (r=2) -> //cdn.example.com/img.jpg (r=3)
    // c=4:                               details (r=2) -> size (r=3) -> 1024 (r=4)
    // c=5:                                                image (r=3) -> width (r=4) -> 800 (r=5)
    // c=6:                                                            -> height (r=4) -> 600 (r=5)

    assert_eq!(engine(2, 2), AxiValue::Str("Hero Image"));
    assert_eq!(engine(4, 4), AxiValue::Num("1024"));
    assert_eq!(engine(5, 5), AxiValue::Num("800"));
    assert_eq!(engine(5, 6), AxiValue::Num("600"));
}
