{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://skinflint.ai/api/ebike-policies.schema.json",
  "title": "Skinflint e-bike return policy feed",
  "description": "Validation contract for the source-dated Skinflint direct-order e-bike return policy and official return-start feed.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "name",
    "version",
    "canonical",
    "schema",
    "license",
    "checked",
    "currency",
    "market",
    "disclaimer",
    "brands"
  ],
  "properties": {
    "name": {
      "type": "string"
    },
    "version": {
      "type": "string"
    },
    "canonical": {
      "type": "string",
      "format": "uri"
    },
    "schema": {
      "type": "string",
      "format": "uri"
    },
    "license": {
      "type": "string",
      "format": "uri"
    },
    "checked": {
      "type": "string",
      "format": "date"
    },
    "currency": {
      "const": "USD"
    },
    "market": {
      "type": "string"
    },
    "disclaimer": {
      "type": "string"
    },
    "brands": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "#/$defs/brand"
      }
    }
  },
  "$defs": {
    "condition": {
      "oneOf": [
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "eligible",
            "fixedMin",
            "fixedMax",
            "unknownFreight"
          ],
          "anyOf": [
            {
              "required": [
                "percent"
              ]
            },
            {
              "required": [
                "percentMin",
                "percentMax"
              ]
            }
          ],
          "properties": {
            "eligible": {
              "const": true
            },
            "percent": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            "percentMin": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            "percentMax": {
              "type": "number",
              "minimum": 0,
              "maximum": 100
            },
            "fixedMin": {
              "type": "number",
              "minimum": 0
            },
            "fixedMax": {
              "type": "number",
              "minimum": 0
            },
            "unknownFreight": {
              "type": "boolean"
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "eligible",
            "reason"
          ],
          "properties": {
            "eligible": {
              "const": false
            },
            "reason": {
              "type": "string",
              "minLength": 1
            }
          }
        }
      ]
    },
    "brand": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "scope",
        "returnDays",
        "returnClock",
        "rideLimit",
        "unopened",
        "ridden",
        "cancellation",
        "cancellationChecked",
        "cancellationCosts",
        "packaging",
        "watchout",
        "returnStart",
        "sourceUrl",
        "shopUrl",
        "sourceLabel",
        "sourceUpdated",
        "anchors",
        "checked"
      ],
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z0-9-]+$"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "scope": {
          "type": "string",
          "minLength": 1
        },
        "returnDays": {
          "type": "integer",
          "minimum": 0
        },
        "returnClock": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "basis",
            "inputLabel",
            "sourceWording",
            "note"
          ],
          "properties": {
            "basis": {
              "enum": [
                "purchase",
                "delivery",
                "receipt",
                "possession"
              ]
            },
            "inputLabel": {
              "type": "string",
              "minLength": 1
            },
            "sourceWording": {
              "type": "string",
              "minLength": 1
            },
            "note": {
              "type": "string",
              "minLength": 1
            }
          }
        },
        "rideLimit": {
          "type": "string",
          "minLength": 1
        },
        "unopened": {
          "$ref": "#/$defs/condition"
        },
        "ridden": {
          "$ref": "#/$defs/condition"
        },
        "cancellation": {
          "type": "string",
          "minLength": 1
        },
        "cancellationChecked": {
          "type": "string",
          "format": "date"
        },
        "cancellationCosts": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "beforeFulfillment",
            "afterFulfillment"
          ],
          "properties": {
            "beforeFulfillment": {
              "type": "object",
              "additionalProperties": false,
              "dependentRequired": {
                "sourceUrl": [
                  "sourceLabel"
                ],
                "sourceLabel": [
                  "sourceUrl"
                ]
              },
              "required": [
                "mode",
                "percent",
                "fixedMin",
                "fixedMax",
                "unknownAdditional",
                "note"
              ],
              "properties": {
                "mode": {
                  "enum": [
                    "free",
                    "fee",
                    "unknown-cost",
                    "not-cancellable",
                    "verify"
                  ]
                },
                "percent": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 100
                },
                "fixedMin": {
                  "type": "number",
                  "minimum": 0
                },
                "fixedMax": {
                  "type": "number",
                  "minimum": 0
                },
                "unknownAdditional": {
                  "type": "boolean"
                },
                "note": {
                  "type": "string",
                  "minLength": 1
                },
                "requestWindowMinutes": {
                  "type": "integer",
                  "minimum": 0
                },
                "sourceUrl": {
                  "type": "string",
                  "format": "uri",
                  "pattern": "^https://"
                },
                "sourceLabel": {
                  "type": "string",
                  "minLength": 1
                }
              }
            },
            "afterFulfillment": {
              "type": "object",
              "additionalProperties": false,
              "dependentRequired": {
                "sourceUrl": [
                  "sourceLabel"
                ],
                "sourceLabel": [
                  "sourceUrl"
                ]
              },
              "required": [
                "mode",
                "percent",
                "fixedMin",
                "fixedMax",
                "unknownAdditional",
                "note"
              ],
              "properties": {
                "mode": {
                  "enum": [
                    "free",
                    "fee",
                    "unknown-cost",
                    "not-cancellable",
                    "verify"
                  ]
                },
                "percent": {
                  "type": "number",
                  "minimum": 0,
                  "maximum": 100
                },
                "fixedMin": {
                  "type": "number",
                  "minimum": 0
                },
                "fixedMax": {
                  "type": "number",
                  "minimum": 0
                },
                "unknownAdditional": {
                  "type": "boolean"
                },
                "note": {
                  "type": "string",
                  "minLength": 1
                },
                "requestWindowMinutes": {
                  "type": "integer",
                  "minimum": 0
                },
                "sourceUrl": {
                  "type": "string",
                  "format": "uri",
                  "pattern": "^https://"
                },
                "sourceLabel": {
                  "type": "string",
                  "minLength": 1
                }
              }
            }
          }
        },
        "returnStart": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "type",
            "url",
            "label",
            "destination",
            "instruction",
            "sourceUrl",
            "checked"
          ],
          "properties": {
            "type": {
              "enum": [
                "email",
                "portal",
                "form"
              ]
            },
            "url": {
              "type": "string",
              "minLength": 1
            },
            "label": {
              "type": "string",
              "minLength": 1
            },
            "destination": {
              "type": "string",
              "minLength": 1
            },
            "instruction": {
              "type": "string",
              "minLength": 1
            },
            "sourceUrl": {
              "type": "string",
              "format": "uri"
            },
            "checked": {
              "type": "string",
              "format": "date"
            }
          }
        },
        "packaging": {
          "type": "string",
          "minLength": 1
        },
        "watchout": {
          "type": "string",
          "minLength": 1
        },
        "sourceUrl": {
          "type": "string",
          "format": "uri"
        },
        "monitorUrl": {
          "type": "string",
          "format": "uri"
        },
        "warrantyUrl": {
          "type": "string",
          "format": "uri"
        },
        "shopUrl": {
          "type": "string",
          "format": "uri"
        },
        "sourceLabel": {
          "type": "string",
          "minLength": 1
        },
        "sourceUpdated": {
          "anyOf": [
            {
              "type": "string",
              "format": "date"
            },
            {
              "type": "null"
            }
          ]
        },
        "anchors": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "checked": {
          "type": "string",
          "format": "date"
        }
      }
    }
  }
}