{
  "format": "cohuno.application/1",
  "project_id": "handbook_orders_training",
  "entrypoints": [
    "main"
  ],
  "processes": [
    {
      "id": "main",
      "name": "Orders training \u00b7 HTTP intake",
      "nodes": [
        {
          "id": "start",
          "name": "Start",
          "type": "start",
          "config": {
            "starter": {
              "kind": "rest"
            },
            "contract": {
              "format": "json",
              "definition": {
                "type": "object",
                "properties": {
                  "path": {
                    "type": "object"
                  },
                  "query": {
                    "type": "object"
                  },
                  "headers": {
                    "type": "object"
                  },
                  "body": {
                    "type": "object",
                    "properties": {
                      "customer": {
                        "type": "string"
                      },
                      "quantity": {
                        "type": "integer"
                      }
                    },
                    "required": [
                      "customer",
                      "quantity"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "path",
                  "query",
                  "headers",
                  "body"
                ],
                "additionalProperties": false
              },
              "source_id": "http_request_schema",
              "source_revision": 1
            }
          },
          "position": {
            "x": 80,
            "y": 180
          }
        },
        {
          "id": "normalize",
          "name": "Normalize",
          "type": "call_process",
          "config": {
            "process_id": "normalize_order",
            "revision": 1,
            "input": {
              "$ref": "/input/body"
            }
          },
          "position": {
            "x": 380,
            "y": 180
          }
        },
        {
          "id": "response",
          "name": "Response",
          "type": "call_process",
          "config": {
            "process_id": "shape_response",
            "revision": 1,
            "input": {
              "$ref": "/last"
            }
          },
          "position": {
            "x": 680,
            "y": 180
          }
        },
        {
          "id": "finish",
          "name": "Finish",
          "type": "end",
          "config": {
            "result": {
              "$ref": "/last"
            },
            "contract": {
              "format": "json",
              "definition": {
                "type": "object",
                "properties": {
                  "accepted": {
                    "type": "boolean"
                  },
                  "order": {
                    "type": "object",
                    "properties": {
                      "customer": {
                        "type": "string"
                      },
                      "quantity": {
                        "type": "integer"
                      }
                    },
                    "required": [
                      "customer",
                      "quantity"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "accepted",
                  "order"
                ],
                "additionalProperties": false
              },
              "source_id": "response_schema",
              "source_revision": 1
            }
          },
          "position": {
            "x": 980,
            "y": 180
          }
        },
        {
          "id": "fault",
          "name": "Catch order failure",
          "type": "catch_all",
          "config": {},
          "position": {
            "x": 80,
            "y": 520
          }
        },
        {
          "id": "log_failure",
          "name": "Log order failure",
          "type": "log",
          "config": {
            "message": "Orders training business flow failed",
            "level": "ERROR"
          },
          "position": {
            "x": 380,
            "y": 520
          }
        },
        {
          "id": "rethrow",
          "name": "Return failure to caller",
          "type": "rethrow",
          "config": {},
          "position": {
            "x": 680,
            "y": 520
          }
        }
      ],
      "edges": [
        {
          "id": "edge_0",
          "source": "start",
          "target": "normalize",
          "kind": "success"
        },
        {
          "id": "edge_1",
          "source": "normalize",
          "target": "response",
          "kind": "success"
        },
        {
          "id": "edge_2",
          "source": "response",
          "target": "finish",
          "kind": "success"
        },
        {
          "id": "fault_log",
          "source": "fault",
          "target": "log_failure",
          "kind": "success"
        },
        {
          "id": "log_rethrow",
          "source": "log_failure",
          "target": "rethrow",
          "kind": "success"
        }
      ],
      "sample_input": {
        "path": {},
        "query": {},
        "headers": {},
        "body": {
          "customer": "  Ada Example  ",
          "quantity": 3
        }
      },
      "folder": "Processes/Orders/Services",
      "description": "Synthetic training: HTTP envelope, pinned normalization and response subprocesses. No external connectors. Saving/importing does not publish this route.",
      "timeout_seconds": 60,
      "max_steps": 250,
      "service": {
        "protocol": "rest",
        "path": "/services/handbook-orders",
        "method": "POST",
        "operation": "HandbookOrders",
        "response_status": 200
      },
      "revision": 1
    },
    {
      "id": "normalize_order",
      "name": "Orders training \u00b7 Normalize order",
      "nodes": [
        {
          "id": "start",
          "name": "Start",
          "type": "start",
          "config": {
            "contract": {
              "format": "json",
              "definition": {
                "type": "object",
                "properties": {
                  "customer": {
                    "type": "string"
                  },
                  "quantity": {
                    "type": "integer"
                  }
                },
                "required": [
                  "customer",
                  "quantity"
                ],
                "additionalProperties": false
              },
              "source_id": "request_schema",
              "source_revision": 1
            }
          },
          "position": {
            "x": 80,
            "y": 180
          }
        },
        {
          "id": "check_quantity",
          "name": "Quantity at least one?",
          "type": "choice",
          "config": {},
          "position": {
            "x": 380,
            "y": 180
          }
        },
        {
          "id": "map_fields",
          "name": "Map Fields",
          "type": "assign",
          "config": {
            "values": {
              "customer": {
                "$fn": {
                  "name": "upper",
                  "args": [
                    {
                      "$fn": {
                        "name": "trim",
                        "args": [
                          {
                            "$ref": "/input/customer"
                          }
                        ]
                      }
                    }
                  ]
                }
              },
              "quantity": {
                "$ref": "/input/quantity"
              }
            },
            "output_mapping": {
              "value": {
                "$ref": "/result"
              }
            }
          },
          "position": {
            "x": 680,
            "y": 180
          }
        },
        {
          "id": "finish",
          "name": "Finish",
          "type": "end",
          "config": {
            "result": {
              "$ref": "/last"
            }
          },
          "position": {
            "x": 980,
            "y": 180
          }
        },
        {
          "id": "invalid_quantity",
          "name": "Reject invalid quantity",
          "type": "throw",
          "config": {
            "code": "quantity_invalid",
            "payload": {
              "reason": "Quantity must be at least one"
            }
          },
          "position": {
            "x": 680,
            "y": 430
          }
        }
      ],
      "edges": [
        {
          "id": "start_check",
          "source": "start",
          "target": "check_quantity",
          "kind": "success"
        },
        {
          "id": "quantity_ok",
          "source": "check_quantity",
          "target": "map_fields",
          "kind": "condition",
          "condition": "number($input/quantity) >= 1",
          "priority": 0,
          "label": "Valid quantity"
        },
        {
          "id": "quantity_otherwise",
          "source": "check_quantity",
          "target": "invalid_quantity",
          "kind": "otherwise",
          "label": "Invalid quantity"
        },
        {
          "id": "map_finish",
          "source": "map_fields",
          "target": "finish",
          "kind": "success"
        }
      ],
      "sample_input": {
        "customer": "  Ada Example  ",
        "quantity": 3
      },
      "folder": "Processes/Orders/Subprocesses",
      "timeout_seconds": 60,
      "max_steps": 250,
      "revision": 1
    },
    {
      "id": "shape_response",
      "name": "Orders training \u00b7 Shape response",
      "nodes": [
        {
          "id": "start",
          "name": "Start",
          "type": "start",
          "config": {
            "contract": {
              "format": "json",
              "definition": {
                "type": "object",
                "properties": {
                  "customer": {
                    "type": "string"
                  },
                  "quantity": {
                    "type": "integer"
                  }
                },
                "required": [
                  "customer",
                  "quantity"
                ],
                "additionalProperties": false
              },
              "source_id": "request_schema",
              "source_revision": 1
            }
          },
          "position": {
            "x": 80,
            "y": 180
          }
        },
        {
          "id": "finish",
          "name": "Finish",
          "type": "end",
          "config": {
            "result": {
              "accepted": true,
              "order": {
                "$ref": "/input"
              }
            },
            "contract": {
              "format": "json",
              "definition": {
                "type": "object",
                "properties": {
                  "accepted": {
                    "type": "boolean"
                  },
                  "order": {
                    "type": "object",
                    "properties": {
                      "customer": {
                        "type": "string"
                      },
                      "quantity": {
                        "type": "integer"
                      }
                    },
                    "required": [
                      "customer",
                      "quantity"
                    ],
                    "additionalProperties": false
                  }
                },
                "required": [
                  "accepted",
                  "order"
                ],
                "additionalProperties": false
              },
              "source_id": "response_schema",
              "source_revision": 1
            }
          },
          "position": {
            "x": 380,
            "y": 180
          }
        }
      ],
      "edges": [
        {
          "id": "edge_0",
          "source": "start",
          "target": "finish",
          "kind": "success"
        }
      ],
      "sample_input": {
        "customer": "ADA EXAMPLE",
        "quantity": 3
      },
      "folder": "Processes/Orders/Subprocesses",
      "timeout_seconds": 60,
      "max_steps": 250,
      "revision": 1
    }
  ],
  "resources": [
    {
      "id": "request_schema",
      "name": "Order body schema",
      "kind": "json_schema",
      "folder": "Schemas",
      "revision": 1,
      "data": {
        "kind": "json_schema",
        "entry": "request_schema.json",
        "files": {
          "request_schema.json": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"customer\": {\n      \"type\": \"string\"\n    },\n    \"quantity\": {\n      \"type\": \"integer\"\n    }\n  },\n  \"required\": [\n    \"customer\",\n    \"quantity\"\n  ],\n  \"additionalProperties\": false\n}"
        }
      }
    },
    {
      "id": "http_request_schema",
      "name": "HTTP order envelope schema",
      "kind": "json_schema",
      "folder": "Schemas",
      "revision": 1,
      "data": {
        "kind": "json_schema",
        "entry": "http_request_schema.json",
        "files": {
          "http_request_schema.json": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"path\": {\n      \"type\": \"object\"\n    },\n    \"query\": {\n      \"type\": \"object\"\n    },\n    \"headers\": {\n      \"type\": \"object\"\n    },\n    \"body\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"customer\": {\n          \"type\": \"string\"\n        },\n        \"quantity\": {\n          \"type\": \"integer\"\n        }\n      },\n      \"required\": [\n        \"customer\",\n        \"quantity\"\n      ],\n      \"additionalProperties\": false\n    }\n  },\n  \"required\": [\n    \"path\",\n    \"query\",\n    \"headers\",\n    \"body\"\n  ],\n  \"additionalProperties\": false\n}"
        }
      }
    },
    {
      "id": "response_schema",
      "name": "Order response schema",
      "kind": "json_schema",
      "folder": "Schemas",
      "revision": 1,
      "data": {
        "kind": "json_schema",
        "entry": "response_schema.json",
        "files": {
          "response_schema.json": "{\n  \"type\": \"object\",\n  \"properties\": {\n    \"accepted\": {\n      \"type\": \"boolean\"\n    },\n    \"order\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"customer\": {\n          \"type\": \"string\"\n        },\n        \"quantity\": {\n          \"type\": \"integer\"\n        }\n      },\n      \"required\": [\n        \"customer\",\n        \"quantity\"\n      ],\n      \"additionalProperties\": false\n    }\n  },\n  \"required\": [\n    \"accepted\",\n    \"order\"\n  ],\n  \"additionalProperties\": false\n}"
        }
      }
    }
  ]
}
