{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://redbook.fun/specification/1.0/schemas/time-rule.schema.json",
  "oneOf": [
    {
      "type": "object",
      "properties": {
        "mode": {
          "const": "none"
        }
      },
      "required": [
        "mode"
      ],
      "additionalProperties": {
        "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json"
      }
    },
    {
      "type": "object",
      "properties": {
        "mode": {
          "const": "earth"
        },
        "calendar": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "mode"
      ],
      "additionalProperties": {
        "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json"
      }
    },
    {
      "type": "object",
      "properties": {
        "mode": {
          "const": "offset"
        },
        "offsetMilliseconds": {
          "type": "string",
          "pattern": "^(?:0|-?[1-9][0-9]*)(?![\\s\\S])"
        },
        "calendar": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "mode"
      ],
      "additionalProperties": {
        "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json"
      }
    },
    {
      "type": "object",
      "properties": {
        "mode": {
          "const": "scaled"
        },
        "realAnchor": {
          "type": "string",
          "pattern": "^[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])T(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\\.[0-9]{3}Z(?![\\s\\S])"
        },
        "worldAnchorMilliseconds": {
          "type": "string",
          "pattern": "^(?:0|-?[1-9][0-9]*)(?![\\s\\S])"
        },
        "rateNumerator": {
          "type": "string",
          "pattern": "^(?:0|-?[1-9][0-9]*)(?![\\s\\S])"
        },
        "rateDenominator": {
          "type": "string",
          "pattern": "^[1-9][0-9]*(?![\\s\\S])"
        },
        "calendar": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "mode",
        "realAnchor",
        "worldAnchorMilliseconds",
        "rateNumerator",
        "rateDenominator"
      ],
      "additionalProperties": {
        "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json"
      }
    },
    {
      "type": "object",
      "properties": {
        "mode": {
          "const": "manual"
        },
        "currentMilliseconds": {
          "type": "string",
          "pattern": "^(?:0|-?[1-9][0-9]*)(?![\\s\\S])"
        },
        "calendar": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "mode",
        "currentMilliseconds"
      ],
      "additionalProperties": {
        "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json"
      }
    },
    {
      "type": "object",
      "properties": {
        "mode": {
          "const": "custom"
        },
        "provider": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "mode",
        "provider"
      ],
      "additionalProperties": {
        "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json"
      }
    }
  ],
  "$defs": {
    "signedMilliseconds": {
      "type": "string",
      "pattern": "^(?:0|-?[1-9][0-9]*)(?![\\s\\S])"
    },
    "timestamp": {
      "type": "string",
      "pattern": "^[0-9]{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])T(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\\.[0-9]{3}Z(?![\\s\\S])"
    },
    "reading": {
      "type": "object",
      "properties": {
        "milliseconds": {
          "type": "string",
          "pattern": "^(?:0|-?[1-9][0-9]*)(?![\\s\\S])"
        },
        "calendar": {
          "type": "string",
          "minLength": 1
        },
        "iso": {
          "oneOf": [
            {
              "type": "string",
              "pattern": "^(?:[0-9]{4}|[+-][0-9]{6})-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])T(?:[01][0-9]|2[0-3]):[0-5][0-9]:[0-5][0-9]\\.[0-9]{3}Z(?![\\s\\S])"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "milliseconds",
        "calendar",
        "iso"
      ],
      "additionalProperties": false
    }
  }
}
