{
	"$schema": "http://json-schema.org/draft-07/schema#",
	"$id": "http://json-schema.int.adscore.com/report/request.schema.json",
	"title": "Generate report",
	"description": "Request a report of traffic processed",
	"type": "object",
	"required": [
		"body"
	],
	"properties": {
		"route": {
			"type": "object",
			"properties": {
				"path": {
					"const": "/account/{id}/report"
				},
				"methods": {
					"const": ["POST"]
				}
			}
		},
		"route_params": {
			"type": "object",
			"description": "Route attributes",
			"required": [
				"id"
			],
			"properties": {
				"id": {
					"type": "integer",
					"description": "Account ID"
				}
			}
		},
		"body": {
			"type": "object",
			"description": "Request body",
			"properties": {
				"volatile": {
					"description": "Determines, whether report results are returned in response for this request (TRUE), or stored for separate download. Defaults to FALSE.",
					"type": "boolean",
					"default": false
				},
				"time_zone": {
					"type": "string",
					"description": "Valid IANA time zone identifier. [https://en.wikipedia.org/wiki/Tz_database]",
					"default": "UTC"
				},
				"column": {
					"type": "array",
					"description": "Additional columns to include in report.",
					"uniqueItems": true,
					"items": {
						"type": "string",
						"enum": ["cost", "result_0_count", "result_0_cost", "result_0_perc", "result_3_count", "result_3_cost", "result_3_perc", "result_6_count", "result_6_cost", "result_6_perc", "result_9_count", "result_9_cost", "result_9_perc"]
					}
				},
				"country_code": {
                    "oneOf": [
                        {
                            "type": "array",
                            "description": "Restricts report results to specified countries. Accepts only valid ISO 3166-1 alpha-2 country codes.",
                            "uniqueItems": true,
                            "items": {
                                "type": "string",
                                "minLength": 2,
                                "maxLength": 2,
                                "pattern": "^[A-Z][A-Z0-2]$"
                            }
                        },
                        {
							"const": null
                        }
                    ]
				},
				"zone_id": {
                    "oneOf": [
                        {
                            "type": "array",
                            "description": "Restricts report results to specified zones.",
                            "uniqueItems": true,
                            "items": {
                                "type": "integer"
                            }
                        },
                        {
							"const": null
                        }
                    ]
				},
                "result": {
                    "oneOf": [
                        {
                            "type": "array",
                            "description": "Restricts report results to specified result codes.",
                            "uniqueItems": true,
                            "items": {
                                "type": "integer"
                            }
                        },
                        {
							"const": null
                        }
                    ]
				},
				"sub_id": {
                    "oneOf": [
                        {
                            "type": "array",
                            "description": "Restricts report results to specified SubIDs.",
                            "uniqueItems": true,
                            "items": {
                                "type": "string"
                            }
                        },
                        {
							"const": null
                        }
                    ]
				},
				"time": {
					"type": "object",
					"description": "Restricts report results to specified time range.",
                    "properties": {
                        "span": {
                            "type": "string",
                            "description": "Predefined time span",
                            "enum": ["total", "today", "yesterday", "this_week", "last_week", "this_month", "last_month", "this_year", "last_year"]
                        },
                        "start": {
                            "type": "string",
                            "description": "Start time (https://www.php.net/manual/en/datetime.formats.php)"
                        },
                        "end": {
                            "type": "string",
                            "description": "End time (https://www.php.net/manual/en/datetime.formats.php)"
                        },
                        "fdow": {
                            "type": "string",
                            "enum": ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"],
                            "description": "First day of week for week boundary calculations"
                        }
                    },
					"additionalProperties": false
				},
				"group": {
					"type": "object",
					"description": "Enables grouping traffic by given criteria.",
					"properties": {
						"zone_id": {
							"type": "boolean",
							"description": "Groups by Zone ID"
						},
						"zone_name": {
							"type": "boolean",
							"description": "Groups by Zone Name"
						},
						"country_code": {
							"type": "boolean",
							"description": "Groups by Country Code"
						},
						"country_name": {
							"type": "boolean",
							"description": "Groups by Country Name"
						},
						"result": {
							"type": "boolean",
							"description": "Groups by numeric Result"
						},
						"result_name": {
							"type": "boolean",
							"description": "Groups by Result (friendly name)"
						},
						"sub_id": {
							"type": "boolean",
							"description": "Groups by SubID"
						},
						"time": {
							"type": "string",
							"enum": ["hour", "day", "week", "month", "year"],
							"description": "Groups by given time span"
						}
					},
					"additionalProperties": false
				},
				"order": {
					"description": "The order parameter should be an object (or array of objects) with a single property representing the column name and its corresponding value as either “ASC” or “DESC”, indicating the desired sorting order",
					"oneOf": [
						{
							"type": "object"
						},
						{
							"type": "array",
							"items": {
								"type": "object"
							}
						}
					]
				},
				"limit": {
					"description": "Maximum number of records, should be set to one higher than desired limit to ensure the requested amount of records are returned",
					"type": "integer"
				},
				"offset": {
					"description": "The offset parameter specifies the starting point of data retrieval and is zero-indexed, meaning the first result starts at offset 0",
					"type": "integer"
				},
				"minimum": {
					"description": "The minimum parameter should be an object with a single property representing the column name and its corresponding value as the minimum value for that column",
					"type": "object"
				},
				"name": {
					"type": "string",
					"maxLength": 255
				},
				"schedule": {
					"oneOf": [
						{
							"const": null
						},
						{
							"type": "object",
							"description": "Schedule settings",
							"required": ["frequency", "time", "email", "format"],
							"properties": {
								"frequency": {
									"type": "string",
									"const": "daily"
								},
								"time": {
									"type": "string",
									"format": "time"
								},
								"email": {
									"description": "Receiver email",
									"oneOf": [
										{
											"type": "string",
											"format": "email"
										},
										{
											"type": "array",
											"uniqueItems": true,
											"items": {
												"type": "string",
												"format": "email",
												"maxItems": 6
											}
										}
									]
								},
								"format": {
									"type": "string",
									"enum": ["pdf", "xlsx", "csv", "ods"]
								},
								"percent": {
									"description": "Should report be expressed in percentages instead of absolute values",
									"type": "boolean",
									"default": false
								},
								"additionalProperties": false
							}
						},
						{
							"type": "object",
							"description": "Schedule settings",
							"required": ["frequency", "day_of_week","time", "email", "format"],
							"properties": {
								"frequency": {
									"type": "string",
									"const": "weekly"
								},
								"day_of_week": {
									"type": "string",
									"enum": ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
								},
								"time": {
									"type": "string",
									"format": "time"
								},
								"email": {
									"description": "Receiver email",
									"oneOf": [
										{
											"type": "string",
											"format": "email"
										},
										{
											"type": "array",
											"uniqueItems": true,
											"items": {
												"type": "string",
												"format": "email",
												"maxItems": 6
											}
										}
									]
								},
								"format": {
									"type": "string",
									"enum": ["pdf", "xlsx", "csv", "ods"]
								},
								"percent": {
									"description": "Should report be expressed in percentages instead of absolute values",
									"type": "boolean",
									"default": false
								},
								"additionalProperties": false
							}
						},
						{
							"type": "object",
							"description": "Schedule settings",
							"required": ["frequency", "day_of_month","time", "email", "format"],
							"properties": {
								"frequency": {
									"type": "string",
									"const": "monthly"
								},
								"day_of_month": {
									"oneOf": [
										{
											"type": "string",
											"const": "last"
										},
										{
											"type": "integer",
											"minimum": 1,
											"maximum": 31
										}
									]
								},
								"time": {
									"type": "string",
									"format": "time"
								},
								"email": {
									"description": "Receiver email",
									"oneOf": [
										{
											"type": "string",
											"format": "email"
										},
										{
											"type": "array",
											"uniqueItems": true,
											"items": {
												"type": "string",
												"format": "email",
												"maxItems": 6
											}
										}
									]
								},
								"percent": {
									"description": "Should report be expressed in percentages instead of absolute values",
									"type": "boolean",
									"default": false
								},
								"format": {
									"type": "string",
									"enum": ["pdf", "xlsx", "csv", "ods"]
								},
								"additionalProperties": false
							}
						}
					]
				}
			},
			"additionalProperties": false
		}
	}
}