{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://torneo.ai/schemas/reference_evidence.v1",
  "title": "reference_evidence.v1",
  "description": "One dated, archived external observation of the data/reference/<R-n>/ ledger read by tools/check_reference.py. Shape only: whether a record counts (external origin, not synthetic, no internal organisation or host, archive bound by sha256, not in the future) is decided by check_reference.accept.",
  "type": "object",
  "required": [
    "schema",
    "signal",
    "synthetic",
    "subject",
    "organisation",
    "observed_on",
    "origin",
    "source_url",
    "archive"
  ],
  "properties": {
    "schema": {
      "const": "reference_evidence.v1"
    },
    "signal": {
      "enum": [
        "R-1",
        "R-2",
        "R-3",
        "R-4",
        "R-5"
      ]
    },
    "synthetic": {
      "type": "boolean",
      "description": "Only false counts (check_reference)."
    },
    "subject": {
      "type": "string",
      "minLength": 1
    },
    "organisation": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "controle_ultime": {
          "type": "string"
        }
      }
    },
    "observed_on": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}"
    },
    "origin": {
      "type": "string",
      "minLength": 1,
      "description": "Only 'external' counts: never an internal probe, a provoked or purchased citation."
    },
    "source_url": {
      "type": "string",
      "minLength": 1
    },
    "archive": {
      "type": "object",
      "required": [
        "path",
        "sha256"
      ],
      "additionalProperties": false,
      "properties": {
        "path": {
          "type": "string",
          "minLength": 1
        },
        "sha256": {
          "type": "string",
          "pattern": "^[0-9a-f]{64}$"
        }
      }
    },
    "via_agent": {
      "type": "boolean"
    },
    "family": {
      "type": "string",
      "minLength": 1
    },
    "reproducer": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "controle_ultime": {
          "type": "string"
        }
      }
    },
    "host": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "controle_ultime": {
          "type": "string"
        }
      }
    },
    "protocol_url": {
      "type": "string",
      "minLength": 1
    },
    "organiser_controller": {
      "type": "string"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "signal": {
            "const": "R-3"
          }
        },
        "required": [
          "signal"
        ]
      },
      "then": {
        "required": [
          "reproducer"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "signal": {
            "const": "R-4"
          }
        },
        "required": [
          "signal"
        ]
      },
      "then": {
        "required": [
          "family"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "signal": {
            "const": "R-5"
          }
        },
        "required": [
          "signal"
        ]
      },
      "then": {
        "required": [
          "protocol_url"
        ]
      }
    }
  ]
}
