{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://pipelinexlab.com/contracts/document-translation.v1.schema.json",
  "title": "Document translation V1",
  "description": "Shape contract. Core also validates language syntax/pair, unique target keys and exact source analysis alignment.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "kind",
    "sourceContentRef",
    "analysisRef",
    "processor",
    "sourceLanguage",
    "targetLanguage",
    "segments"
  ],
  "properties": {
    "schemaVersion": {
      "const": 1
    },
    "kind": {
      "const": "document-translation"
    },
    "sourceContentRef": {
      "$ref": "#/$defs/digest"
    },
    "analysisRef": {
      "$ref": "#/$defs/digest"
    },
    "processor": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "engineKey",
        "engineVersion",
        "modelRefs",
        "configurationRef"
      ],
      "properties": {
        "engineKey": {
          "$ref": "#/$defs/key"
        },
        "engineVersion": {
          "type": "string",
          "minLength": 1
        },
        "modelRefs": {
          "type": "array",
          "uniqueItems": true,
          "items": {
            "$ref": "#/$defs/digest"
          }
        },
        "configurationRef": {
          "$ref": "#/$defs/digest"
        }
      }
    },
    "sourceLanguage": {
      "type": "string",
      "minLength": 1
    },
    "targetLanguage": {
      "type": "string",
      "minLength": 1
    },
    "segments": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "key",
          "sourceSegmentKeys",
          "text"
        ],
        "properties": {
          "key": {
            "$ref": "#/$defs/key"
          },
          "sourceSegmentKeys": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "items": {
              "$ref": "#/$defs/key"
            }
          },
          "text": {
            "type": "string"
          },
          "confidence": {
            "anyOf": [
              {
                "type": "null"
              },
              {
                "$ref": "#/$defs/unit"
              }
            ]
          }
        }
      }
    }
  },
  "$defs": {
    "digest": {
      "type": "string",
      "pattern": "^sha256:[0-9a-f]{64}$"
    },
    "key": {
      "type": "string",
      "maxLength": 128,
      "pattern": "^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$"
    },
    "decimal": {
      "type": "string",
      "pattern": "^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]*[1-9])?$",
      "not": {
        "const": "-0"
      },
      "maxLength": 40
    },
    "unit": {
      "type": "string",
      "pattern": "^(?:0(?:\\.[0-9]{0,17}[1-9])?|1)$"
    }
  }
}
