{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://json-schema.int.adscore.com/zone/code_generate.schema.json",
  "title": "Zone Code Generation",
  "description": "Generate code for Zone",
  "type": "object",
  "required": [
    "route_params",
    "body"
  ],
  "properties": {
    "route": {
      "type": "object",
      "properties": {
        "path": {
          "const": "/account/{account_id}/zone/{id}/code"
        },
        "methods": {
          "const": [
            "POST"
          ]
        }
      }
    },
    "route_params": {
      "type": "object",
      "description": "Route attributes",
      "required": [
        "account_id",
        "id"
      ],
      "properties": {
        "account_id": {
          "type": "integer"
        },
        "id": {
          "type": "integer"
        }
      }
    },
    "body": {
      "anyOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "compliant",
            "type",
            "data"
          ],
          "properties": {
            "type": {
              "type": "string",
              "description": "Type",
              "const": "link_iframe"
            },
            "referrer": {
              "$ref": "#/definitions/referrer"
            },
            "compliant": {
              "$ref": "#/definitions/compliant"
            },
            "sub_id": {
              "$ref": "#/definitions/sub_id"
            },
            "ipv6_priority": {
              "$ref": "#/definitions/ipv6_priority"
            },
            "lite": {
              "$ref": "#/definitions/lite"
            },
            "async_callback": {
              "$ref": "#/definitions/async_callback"
            },
            "data" : {
              "$ref": "#/definitions/data_link"
            },
            "compatibility": {
              "$ref": "#/definitions/compatibility"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "compliant",
            "type",
            "data"
          ],
          "properties": {
            "type": {
              "type": "string",
              "description": "Type",
              "const": "link_redirect"
            },
            "referrer": {
              "$ref": "#/definitions/referrer"
            },
            "compliant": {
              "$ref": "#/definitions/compliant"
            },
            "sub_id": {
              "$ref": "#/definitions/sub_id"
            },
            "ipv6_priority": {
              "$ref": "#/definitions/ipv6_priority"
            },
            "lite": {
              "$ref": "#/definitions/lite"
            },
            "async_callback": {
              "$ref": "#/definitions/async_callback"
            },
            "prefetch_mode": {
              "$ref": "#/definitions/prefetch_mode"
            },
            "data" : {
              "$ref": "#/definitions/data_link"
            },
            "compatibility": {
              "$ref": "#/definitions/compatibility"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "compliant",
            "type",
            "data"
          ],
          "properties": {
            "type": {
              "type": "string",
              "description": "Type",
              "const": "link_redirect_conditional"
            },
            "referrer": {
              "$ref": "#/definitions/referrer"
            },
            "compliant": {
              "$ref": "#/definitions/compliant"
            },
            "sub_id": {
              "$ref": "#/definitions/sub_id"
            },
            "ipv6_priority": {
              "$ref": "#/definitions/ipv6_priority"
            },
            "lite": {
              "$ref": "#/definitions/lite"
            },
            "async_callback": {
              "$ref": "#/definitions/async_callback"
            },
            "data" : {
              "$ref": "#/definitions/data_link_conditional"
            },
            "compatibility": {
              "$ref": "#/definitions/compatibility"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "type",
            "data"
          ],
          "properties": {
            "type": {
              "type": "string",
              "description": "Type",
              "enum": ["js_api_conditional", "js_proxy_conditional", "cloudflare_worker"]
            },
            "referrer": {
              "$ref": "#/definitions/referrer"
            },
            "sub_id": {
              "$ref": "#/definitions/sub_id"
            },
            "ipv6_priority": {
              "$ref": "#/definitions/ipv6_priority"
            },
            "lite": {
              "$ref": "#/definitions/lite"
            },
            "async_callback": {
              "$ref": "#/definitions/async_callback"
            },
            "data" : {
              "$ref": "#/definitions/data_conditional"
            },
            "compatibility": {
              "$ref": "#/definitions/compatibility"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "type"
          ],
          "properties": {
            "type": {
              "type": "string",
              "description": "Type",
              "enum": ["js_tag", "js_api"]
            },
            "referrer": {
              "$ref": "#/definitions/referrer"
            },
            "sub_id": {
              "$ref": "#/definitions/sub_id"
            },
            "ipv6_priority": {
              "$ref": "#/definitions/ipv6_priority"
            },
            "lite": {
              "$ref": "#/definitions/lite"
            },
            "async_callback": {
              "$ref": "#/definitions/async_callback"
            },
            "compatibility": {
              "$ref": "#/definitions/compatibility"
            }
          }
        }
      ],
      "description": "Request body"
    }
  },
  "definitions": {
      "compatibility": {
        "type": "boolean",
        "description": "Compatibility mode enforces usage of ? symbol instead of #. Use when standard generated URL is invalid for your needs.",
        "default": false
      },
      "compliant": {
        "type": "boolean",
        "description": "Compliant with RFC 3986",
        "default": false
      },
      "referrer": {
        "type": "string",
        "description": "When set to no-referrer, the redirection to the target URL will not carry referrer header (ie. blank referrer).",
        "enum": ["origin", "no-referrer"],
        "default": "origin",
        "$filters": {
          "$func": "remove_if_default",
          "$vars": {
            "path": "$.body.referrer",
            "value": "origin"
          }
        }
      },
      "sub_id": {
        "description": "Subzone ID",
        "oneOf": [
          {
            "type": "string",
            "maxLength": 256
          },
          {
            "type": "number",
            "minimum": 0
          }
        ]
      },
      "ipv6_priority": {
        "type": "integer",
        "description": "By default, Adscore works on IPv4 with additional IPv6 gatherer. This means that Adscore will always know the visitor IPv4 address and in most cases, if visitor has it, IPv6 address.\nIn case you use Adscore Signature to verify traffic in your backend and your website uses IPv6, there is a possibility that our system will see only the IPv4 address (and use it for the signature) and your system will see only the IPv6 address. In such a case, the signature verification will fail. To resolve this problem, you can set ipv6_priority to 1 which will force Adscore to work on IPv6 as the primary visitor address.",
        "minimum": 0,
        "maximum": 1,
        "default": 0,
        "$filters": {
          "$func": "remove_if_default",
          "$vars": {
            "path": "$.body.ipv6_priority",
            "value": 0
          }
        }
      },
      "lite": {
        "type": "integer",
        "description": "Some Adscore client-side modules which test visitor’s hardware, mainly GPU, tend to be time and resource consuming. On modern devices they usually take a couple hundred milliseconds, however in some cases this can take up to a few seconds (for example virtual machines). Setting the lite parameter to 1 will disable these modules, which will lower the detection quality (in certain, rare cases), but will reduce the client-side processing time by around 70% on average. \n Please make sure to set Allow Adscore Lite Processing in Zone Settings to Yes. Failing to do so will result in all traffic to be detected as bot.",
        "minimum": 0,
        "maximum": 1,
        "default": 0,
        "$filters": {
          "$func": "remove_if_default",
          "$vars": {
            "path": "$.body.lite",
            "value": 0
          }
        }
      },
      "async_callback": {
        "type": "integer",
        "description": "By default, Adscore Javascript module will first gather all necessary data, then send it to our backend and then wait for the backend response to be able to provide you Adscore Signature through the callback. In some cases however, the signature is not necessary so waiting for the backend response is not needed either. In such a case, setting async_callback to 1 will make our code send data to our backend using navigator.sendBeacon, allowing us to speed up client-side processing. Your callback will be executed immediately after data is queued to be sent to our backend, but obviously will not have any values in the result object.\nHowever, doing so will also make it not possible for our system to cache verification results. This means that all subsequent hits by the same visitor will require full analysis to be repeated each time, which will not be optimal from a performance point of view. For this reason, the async_callback option should only be used on unique traffic, where one visitor is verified only once.",
        "minimum": 0,
        "maximum": 1,
        "default": 0,
        "$filters": {
          "$func": "remove_if_default",
          "$vars": {
            "path": "$.body.async_callback",
            "value": 0
          }
        }
      },
      "prefetch_mode": {
        "type": "string",
        "description": "preload - (maximal performance, might cause partial double counting by trackers)\nnone - (lower performance, won't cause double counting by trackers)\npreconnect - (partial performance benefits, won't cause double counting by trackers)",
        "default": "preload",
        "enum": ["preload", "none", "preconnect"],
        "$filters": {
          "$func": "remove_if_default",
          "$vars": {
            "path": "$.body.prefetch_mode",
            "value": "preload"
          }
        }
      },
      "data_link_conditional": {
        "type": "object",
        "required": [
          "expect",
          "pass"
        ],
        "properties": {
          "expect": {
            "type": "array",
            "format": "judge_result_names",
            "description": "Expected judge result. Any of:  [\"ok\", \"junk\", \"proxy\", \"bot\"]"
          },
          "pass": {
            "type": "string",
            "format": "url_with_parameters",
            "description": "Url when passed judge, can contain custom parameters enclosed in one of formats: $[name] [name] ${name} {name}"
          },
          "fail": {
            "type": "string",
            "format": "url_with_parameters",
            "description": "Url when failed judge, can contain parameters enclosed in one of formats: $[name] [name] ${name} {name}"
          }
        }
      },
      "data_conditional": {
        "type": "object",
        "required": [
          "expect"
        ],
        "properties": {
          "expect": {
            "type": "array",
            "format": "judge_result_names",
            "description": "Expected judge result. Any of:  [\"ok\", \"junk\", \"proxy\", \"bot\"]"
          }
        }
      },
      "data_link" : {
        "type": "string",
        "format": "url_with_parameters",
        "description": "Redirection URL, can contain parameters enclosed in one of formats: $[name] [name] ${name} {name}"
      }
    }
}
