type "OrderOutput" {
    struct {
        field "id" {
            primitive "integer"
        }
        field "user_id" {
            primitive "integer"
        }
        field "total" {
            primitive "integer"
        }
    }
}
type "echoInput" {
    struct {
        field "text" {
            primitive "string"
        }
    }
}
type "echoOutput" {
    struct {
        field "message" {
            primitive "string"
        }
    }
}
type "findUserInput" {
    struct {
        field "user_id" {
            primitive "integer"
        }
    }
}
type "findUserOutput" {
    struct {
        field "user_id" {
            primitive "integer"
        }
        field "name" {
            primitive "string"
        }
    }
}
type "renameUserInput" {
    struct {
        field "user_id" {
            primitive "integer"
        }
        field "name" {
            primitive "string"
        }
    }
}
type "renameUserOutput" {
    struct {
        field "user_id" {
            primitive "integer"
        }
        field "name" {
            primitive "string"
        }
    }
}
type "updateProfileInput" {
    struct {
        field "user_id" {
            primitive "integer"
        }
        field "name" {
            primitive "string"
        }
    }
}
type "updateProfileOutput" {
    struct {
        field "ok" {
            primitive "boolean"
        }
    }
}
type "userOrdersInput" {
    struct {
        field "user_id" {
            primitive "integer"
        }
    }
}
type "userOrdersOutput" {
    alias {
        list {
            ref "OrderOutput"
        }
    }
}
type "userProfileInput" {
    struct {
        field "user_id" {
            primitive "integer"
        }
    }
}
type "userProfileOutput" {
    struct {
        field "user_id" {
            primitive "integer"
        }
        field "name" {
            primitive "string"
        }
    }
}
type "whoamiOutput" {
    struct {
        field "email" {
            primitive "string"
        }
        field "authenticated" {
            primitive "boolean"
        }
    }
}

function "echo" {
    camel "echo"
    has-input #true
    input "echoInput"
    output "echoOutput"
    transport "http"
}
function "find_user" {
    camel "findUser"
    has-input #true
    input "findUserInput"
    output "findUserOutput"
    output-nullable #true
    transport "http"
}
function "rename_user" {
    camel "renameUser"
    has-input #true
    input "renameUserInput"
    output "renameUserOutput"
    transport "http"
    merge "user"
}
function "update_profile" {
    camel "updateProfile"
    has-input #true
    input "updateProfileInput"
    output "updateProfileOutput"
    transport "http"
    affects "user"
}
function "user_orders" {
    camel "userOrders"
    has-input #true
    input "userOrdersInput"
    output "userOrdersOutput"
    transport "http"
    context "user"
}
function "user_profile" {
    camel "userProfile"
    has-input #true
    input "userProfileInput"
    output "userProfileOutput"
    transport "http"
    context "user"
}
function "whoami" {
    camel "whoami"
    has-input #false
    output "whoamiOutput"
    transport "http"
}

context "user" {
    function "user_orders"
    function "user_profile"
    param "user_id" {
        type "integer"
        required #true
        shared-by "user_orders"
        shared-by "user_profile"
    }
}
