{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://qaechi.github.io/schemas/v1/job-message.schema.json",
  "$defs": {
    "FieldSpec": {
      "description": "A field the caller wants extracted.",
      "properties": {
        "name": {
          "pattern": "^[A-Za-z_][A-Za-z0-9_]{0,63}$",
          "title": "Name",
          "type": "string"
        },
        "kind": {
          "default": "text",
          "enum": [
            "text",
            "integer",
            "number",
            "date"
          ],
          "title": "Kind",
          "type": "string"
        },
        "description": {
          "default": "",
          "maxLength": 500,
          "title": "Description",
          "type": "string"
        }
      },
      "required": [
        "name"
      ],
      "title": "FieldSpec",
      "type": "object"
    },
    "JobRequest": {
      "description": "What to parse. Same body as `POST /jobs`.",
      "properties": {
        "documentId": {
          "maxLength": 200,
          "minLength": 1,
          "title": "Documentid",
          "type": "string"
        },
        "source": {
          "description": "Path relative to the parser's configured source",
          "maxLength": 1000,
          "minLength": 1,
          "title": "Source",
          "type": "string"
        },
        "docType": {
          "maxLength": 64,
          "minLength": 1,
          "title": "Doctype",
          "type": "string"
        },
        "fields": {
          "items": {
            "$ref": "#/$defs/FieldSpec"
          },
          "maxItems": 50,
          "title": "Fields",
          "type": "array"
        },
        "lines": {
          "default": false,
          "title": "Lines",
          "type": "boolean"
        },
        "period": {
          "anyOf": [
            {
              "maxLength": 32,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Period"
        },
        "sourceKind": {
          "anyOf": [
            {
              "maxLength": 64,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "title": "Sourcekind"
        },
        "requestedBy": {
          "anyOf": [
            {
              "maxLength": 200,
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "default": null,
          "description": "Audit only; the parser does not authorize users",
          "title": "Requestedby"
        }
      },
      "required": [
        "documentId",
        "source",
        "docType"
      ],
      "title": "JobRequest",
      "type": "object"
    }
  },
  "description": "Kafka topic `qaechi.parse.jobs`, key = documentId. Any system may publish one.",
  "properties": {
    "specVersion": {
      "const": "1",
      "default": "1",
      "title": "Specversion",
      "type": "string"
    },
    "jobId": {
      "maxLength": 200,
      "minLength": 1,
      "title": "Jobid",
      "type": "string"
    },
    "request": {
      "$ref": "#/$defs/JobRequest"
    }
  },
  "required": [
    "jobId",
    "request"
  ],
  "title": "JobMessage",
  "type": "object"
}
