{
    "kind": "module",
    "id": "mod-approval-demo",
    "name": "approval_demo",
    "imports": [],
    "definitions": [
        {
            "kind": "fn",
            "id": "fn-transfer",
            "name": "transfer_funds",
            "params": [
                { "kind": "param", "id": "p-amount", "name": "amount", "type": { "kind": "basic", "name": "Int" } },
                { "kind": "param", "id": "p-dest", "name": "destination", "type": { "kind": "basic", "name": "String" } }
            ],
            "effects": ["io"],
            "returnType": { "kind": "basic", "name": "Int" },
            "contracts": [
                {
                    "kind": "pre",
                    "id": "pre-positive",
                    "condition": {
                        "kind": "binop", "id": "cmp-gt0", "op": ">",
                        "left":  { "kind": "ident", "id": "id-amount-pre", "name": "amount" },
                        "right": { "kind": "literal", "id": "lit-0-pre", "value": 0 }
                    }
                }
            ],
            "approval": {
                "required": true,
                "scope": "per_call",
                "reason": "wire_transfer"
            },
            "body": [
                { "kind": "ident", "id": "id-amount-ret", "name": "amount" }
            ]
        },
        {
            "kind": "fn",
            "id": "fn-process",
            "name": "process_payment",
            "params": [
                { "kind": "param", "id": "p-amt", "name": "amt", "type": { "kind": "basic", "name": "Int" } }
            ],
            "effects": ["io"],
            "returnType": { "kind": "basic", "name": "Int" },
            "contracts": [],
            "approval": {
                "required": true,
                "scope": "per_call",
                "reason": "wire_transfer"
            },
            "body": [
                {
                    "kind": "call", "id": "call-transfer",
                    "fn": { "kind": "ident", "id": "id-transfer", "name": "transfer_funds" },
                    "args": [
                        { "kind": "ident", "id": "id-amt", "name": "amt" },
                        { "kind": "literal", "id": "lit-dest", "value": "bank://acme" }
                    ]
                }
            ]
        },
        {
            "kind": "fn",
            "id": "fn-main",
            "name": "main",
            "params": [],
            "effects": ["io"],
            "returnType": { "kind": "basic", "name": "Int" },
            "contracts": [],
            "approval": {
                "required": true,
                "scope": "per_session",
                "reason": "payment_processing"
            },
            "body": [
                {
                    "kind": "call", "id": "call-process",
                    "fn": { "kind": "ident", "id": "id-process", "name": "process_payment" },
                    "args": [
                        { "kind": "literal", "id": "lit-100", "value": 100 }
                    ]
                }
            ]
        }
    ]
}
