{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://redbook.fun/specification/1.0/schemas/host-job.schema.json",
  "type": "object",
  "properties": {
    "jobId": {
      "type": "string",
      "minLength": 1
    },
    "operation": {
      "type": "string",
      "minLength": 1
    },
    "status": {
      "enum": [
        "pending",
        "running",
        "succeeded",
        "failed",
        "cancelled",
        "uncertain"
      ]
    },
    "result": {
      "$ref": "https://redbook.fun/specification/1.0/schemas/value.schema.json"
    },
    "error": {
      "type": "object",
      "properties": {
        "code": {
          "type": "string",
          "minLength": 1
        },
        "message": {
          "type": "string"
        },
        "retryable": {
          "type": "boolean"
        }
      },
      "required": [
        "code",
        "message",
        "retryable"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "jobId",
    "operation",
    "status"
  ],
  "additionalProperties": false,
  "allOf": [
    {
      "if": {
        "properties": {
          "status": {
            "const": "succeeded"
          }
        }
      },
      "then": {
        "required": [
          "result"
        ],
        "not": {
          "required": [
            "error"
          ]
        }
      }
    },
    {
      "if": {
        "properties": {
          "status": {
            "enum": [
              "failed",
              "uncertain"
            ]
          }
        }
      },
      "then": {
        "required": [
          "error"
        ],
        "not": {
          "required": [
            "result"
          ]
        }
      }
    },
    {
      "if": {
        "properties": {
          "status": {
            "enum": [
              "pending",
              "running",
              "cancelled"
            ]
          }
        }
      },
      "then": {
        "not": {
          "anyOf": [
            {
              "required": [
                "result"
              ]
            },
            {
              "required": [
                "error"
              ]
            }
          ]
        }
      }
    }
  ]
}
