{
  "version": "7.1",
  "data_api_version": "3.0",
  "routing_model": {
    "TERMS": [
      "SEARCH"
    ],
    "SEARCH": [
      "RESULTS"
    ],
    "RESULTS": [
      "PRODUCT"
    ],
    "PRODUCT": [
      "DONE"
    ],
    "DONE": []
  },
  "screens": [
    {
      "id": "TERMS",
      "title": "Terms & Conditions",
      "data": {
        "summary": {
          "type": "string",
          "__example__": "Please review our shopping terms."
        },
        "terms_url": {
          "type": "string",
          "__example__": "https://example.com/terms"
        },
        "privacy_url": {
          "type": "string",
          "__example__": "https://example.com/privacy"
        },
        "message": {
          "type": "string",
          "__example__": ""
        }
      },
      "layout": {
        "type": "SingleColumnLayout",
        "children": [
          {
            "type": "Form",
            "name": "form",
            "children": [
              {
                "type": "TextHeading",
                "text": "Before you shop"
              },
              {
                "type": "TextBody",
                "text": "${data.summary}"
              },
              {
                "type": "EmbeddedLink",
                "text": "Read full terms",
                "on-click-action": {
                  "name": "open_url",
                  "url": "${data.terms_url}"
                }
              },
              {
                "type": "EmbeddedLink",
                "text": "Privacy policy",
                "on-click-action": {
                  "name": "open_url",
                  "url": "${data.privacy_url}"
                }
              },
              {
                "type": "TextBody",
                "text": "${data.message}"
              },
              {
                "type": "OptIn",
                "name": "accepted",
                "label": "I accept the Terms & Conditions",
                "required": true
              },
              {
                "type": "Footer",
                "label": "Agree and continue",
                "on-click-action": {
                  "name": "data_exchange",
                  "payload": {
                    "accepted": "${form.accepted}"
                  }
                }
              }
            ]
          }
        ]
      }
    },
    {
      "id": "SEARCH",
      "title": "Search products",
      "data": {
        "categories": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "title": {
                "type": "string"
              }
            }
          },
          "__example__": [
            {
              "id": "all",
              "title": "All products"
            }
          ]
        },
        "message": {
          "type": "string",
          "__example__": ""
        }
      },
      "layout": {
        "type": "SingleColumnLayout",
        "children": [
          {
            "type": "Form",
            "name": "form",
            "children": [
              {
                "type": "TextHeading",
                "text": "What are you looking for?"
              },
              {
                "type": "TextBody",
                "text": "${data.message}"
              },
              {
                "type": "TextInput",
                "name": "query",
                "label": "Product name or SKU",
                "input-type": "text",
                "max-chars": 100
              },
              {
                "type": "Dropdown",
                "name": "category",
                "label": "Category",
                "required": true,
                "data-source": "${data.categories}"
              },
              {
                "type": "Footer",
                "label": "Search",
                "on-click-action": {
                  "name": "data_exchange",
                  "payload": {
                    "query": "${form.query}",
                    "category": "${form.category}"
                  }
                }
              }
            ]
          }
        ]
      }
    },
    {
      "id": "RESULTS",
      "title": "Search results",
      "data": {
        "products": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "title": {
                "type": "string"
              },
              "description": {
                "type": "string"
              },
              "enabled": {
                "type": "boolean"
              }
            }
          },
          "__example__": [
            {
              "id": "product-id",
              "title": "Milk 1L",
              "description": "USD 1.60 \u00b7 In stock",
              "enabled": true
            }
          ]
        },
        "message": {
          "type": "string",
          "__example__": "Showing up to 20 results."
        }
      },
      "layout": {
        "type": "SingleColumnLayout",
        "children": [
          {
            "type": "Form",
            "name": "form",
            "children": [
              {
                "type": "TextBody",
                "text": "${data.message}"
              },
              {
                "type": "RadioButtonsGroup",
                "name": "product",
                "label": "Choose a product",
                "required": true,
                "data-source": "${data.products}"
              },
              {
                "type": "Footer",
                "label": "View product",
                "on-click-action": {
                  "name": "data_exchange",
                  "payload": {
                    "product": "${form.product}"
                  }
                }
              }
            ]
          }
        ]
      }
    },
    {
      "id": "PRODUCT",
      "title": "Product details",
      "data": {
        "name": {
          "type": "string",
          "__example__": "Milk 1L"
        },
        "price": {
          "type": "string",
          "__example__": "USD 1.60"
        },
        "stock": {
          "type": "string",
          "__example__": "In stock"
        },
        "image": {
          "type": "string",
          "__example__": "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII="
        },
        "quantities": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "title": {
                "type": "string"
              }
            }
          },
          "__example__": [
            {
              "id": "1",
              "title": "1"
            }
          ]
        },
        "message": {
          "type": "string",
          "__example__": ""
        }
      },
      "layout": {
        "type": "SingleColumnLayout",
        "children": [
          {
            "type": "Form",
            "name": "form",
            "children": [
              {
                "type": "Image",
                "src": "${data.image}",
                "width": 240,
                "height": 200,
                "scale-type": "contain",
                "alt-text": "Product image"
              },
              {
                "type": "TextHeading",
                "text": "${data.name}"
              },
              {
                "type": "TextBody",
                "text": "${data.price}"
              },
              {
                "type": "TextBody",
                "text": "${data.stock}"
              },
              {
                "type": "TextBody",
                "text": "${data.message}"
              },
              {
                "type": "Dropdown",
                "name": "quantity",
                "label": "Quantity",
                "required": true,
                "data-source": "${data.quantities}"
              },
              {
                "type": "Footer",
                "label": "Add to basket",
                "on-click-action": {
                  "name": "data_exchange",
                  "payload": {
                    "quantity": "${form.quantity}"
                  }
                }
              }
            ]
          }
        ]
      }
    },
    {
      "id": "DONE",
      "title": "Added to basket",
      "data": {
        "message": {
          "type": "string",
          "__example__": "Product added to your basket."
        }
      },
      "layout": {
        "type": "SingleColumnLayout",
        "children": [
          {
            "type": "Form",
            "name": "form",
            "children": [
              {
                "type": "TextBody",
                "text": "${data.message}"
              },
              {
                "type": "Footer",
                "label": "View basket in chat",
                "on-click-action": {
                  "name": "complete",
                  "payload": {
                    "value": "flow_cart"
                  }
                }
              }
            ]
          }
        ]
      },
      "terminal": true,
      "success": true
    }
  ]
}
