{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "state": {
      "type": "string",
      "enum": ["active", "paused", "archived"]
    },
    "schedules": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "declaration": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9-]{0,63}$"
                  },
                  "path": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 512
                  },
                  "description": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  },
                  "every": {
                    "type": "string",
                    "pattern": "^[1-9]\\d{0,3}[mhd]$"
                  }
                },
                "required": ["name", "path", "description", "every"]
              },
              {
                "type": "object",
                "properties": {
                  "name": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9-]{0,63}$"
                  },
                  "path": {
                    "type": "string",
                    "minLength": 2,
                    "maxLength": 512
                  },
                  "description": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 500
                  },
                  "cron": {
                    "type": "string",
                    "maxLength": 120
                  }
                },
                "required": ["name", "path", "description", "cron"]
              }
            ]
          },
          "nextRun": {
            "anyOf": [
              {
                "type": "number"
              },
              {
                "type": "null"
              }
            ]
          },
          "blocked": {
            "type": "boolean"
          },
          "lastRun": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "build": {
                    "type": "string",
                    "format": "uuid",
                    "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                  },
                  "startedAt": {
                    "type": "number"
                  },
                  "scheduledAt": {
                    "type": "number"
                  },
                  "manual": {
                    "type": "boolean"
                  },
                  "status": {
                    "type": "string",
                    "enum": [
                      "queued",
                      "running",
                      "succeeded",
                      "failed",
                      "uncertain"
                    ]
                  },
                  "duration": {
                    "anyOf": [
                      {
                        "type": "number"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "error": {
                    "anyOf": [
                      {
                        "type": "string"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "result": {
                    "anyOf": [
                      {
                        "type": "object",
                        "properties": {
                          "outcome": {
                            "type": "string",
                            "enum": ["succeeded", "partial", "failed"]
                          },
                          "summary": {
                            "type": "string",
                            "minLength": 1,
                            "maxLength": 500
                          },
                          "metrics": {
                            "type": "object",
                            "propertyNames": {
                              "type": "string",
                              "pattern": "^[A-Za-z][\\w.-]{0,63}$"
                            },
                            "additionalProperties": {
                              "type": "number"
                            }
                          },
                          "diagnostics": {
                            "maxItems": 50,
                            "type": "array",
                            "items": {
                              "type": "object",
                              "properties": {
                                "level": {
                                  "type": "string",
                                  "enum": ["error", "warning", "info"]
                                },
                                "message": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 500
                                },
                                "subject": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 200
                                },
                                "code": {
                                  "type": "string",
                                  "minLength": 1,
                                  "maxLength": 100
                                }
                              },
                              "required": ["level", "message"]
                            }
                          }
                        },
                        "required": ["outcome"]
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": [
                  "id",
                  "build",
                  "startedAt",
                  "scheduledAt",
                  "manual",
                  "status",
                  "duration",
                  "error"
                ]
              },
              {
                "type": "null"
              }
            ]
          }
        },
        "required": ["declaration", "nextRun", "blocked", "lastRun"]
      }
    },
    "environment": {
      "description": "The environment the command used: test unless --environment live was given.",
      "type": "string",
      "enum": ["test", "live"]
    }
  },
  "required": ["state", "schedules"]
}
