{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openeik.org/schemas/0.1/proposed/drawings/provenance.schema.json",
  "$comment": "Proposed for OpenEik 0.2: Part XIV, drawings. Written by hand from the outline of Part XIV, not generated: tools/generate-schemas.mjs keeps this folder and lists none of it in index.json. In 0.1, provenance is a member a detail item's schema does not know; a validator holds it to this schema only when asked for the proposal (@openeik/tools: proposals [\"drawings\"]).",
  "title": "Detail item provenance",
  "description": "Who made a detail item (Part XIV, 3.2, proposed for 0.2). An item an agent writes carries it: the agent, the person it acts for, the instruction by its SHA-256 and an opaque reference under access control (never the instruction's text), the model version it saw, and its status, proposed until a person accepts it, then accepted, with who accepted it and when. The AI rule: a person accepts every agent's item, and no sheet is issued while it holds a proposed item.",
  "type": "object",
  "properties": {
    "by": {
      "type": "string",
      "enum": [
        "person",
        "agent"
      ]
    },
    "person": {
      "description": "For person: who drew it.",
      "$ref": "defs.schema.json#/$defs/person"
    },
    "agent": {
      "description": "For agent: the agent.",
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 120
        },
        "version": {
          "type": "string",
          "minLength": 1,
          "maxLength": 80
        }
      },
      "required": [
        "name",
        "version"
      ],
      "x-eik-closed": true
    },
    "actingFor": {
      "description": "For agent: the person it acts for.",
      "$ref": "defs.schema.json#/$defs/person"
    },
    "instruction": {
      "description": "For agent: the SHA-256 of the instruction, and an opaque reference to it under access control. Nothing else: never the instruction's text (XIV.3.4, rule 5).",
      "type": "object",
      "properties": {
        "digest": {
          "$ref": "defs.schema.json#/$defs/hash"
        },
        "ref": {
          "type": "string",
          "minLength": 1,
          "maxLength": 400
        }
      },
      "required": [
        "digest"
      ],
      "additionalProperties": false
    },
    "made": {
      "description": "For agent: the model version it saw, as Part VI, 8.2's computedFrom.version, and the root tree hash.",
      "type": "object",
      "properties": {
        "version": {
          "$ref": "defs.schema.json#/$defs/version"
        },
        "root": {
          "$ref": "defs.schema.json#/$defs/hash"
        }
      },
      "required": [
        "version"
      ],
      "x-eik-closed": true
    },
    "status": {
      "type": "string",
      "enum": [
        "proposed",
        "accepted"
      ]
    },
    "acceptedBy": {
      "description": "When accepted: the person who accepted it.",
      "$ref": "defs.schema.json#/$defs/person"
    },
    "acceptedAt": {
      "description": "When accepted: when.",
      "$ref": "defs.schema.json#/$defs/time"
    }
  },
  "required": [
    "by"
  ],
  "allOf": [
    {
      "if": {
        "properties": {
          "by": {
            "const": "agent"
          }
        },
        "required": [
          "by"
        ]
      },
      "then": {
        "required": [
          "agent",
          "actingFor",
          "instruction",
          "made",
          "status"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "status": {
            "const": "accepted"
          }
        },
        "required": [
          "status"
        ]
      },
      "then": {
        "required": [
          "acceptedBy",
          "acceptedAt"
        ]
      }
    }
  ],
  "x-eik-closed": true
}
