{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://soqver.com/spec/so4ag/0.1/schema.json",
  "title": "SO4AG 0.1 source manifest (draft)",
  "description": "Structural schema. Semantic rules (time order, profile rules, digests) are defined in the specification and checked by the validator.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "so4ag",
    "id",
    "revision",
    "published_at",
    "publisher",
    "claims"
  ],
  "properties": {
    "so4ag": {
      "const": "0.1-draft"
    },
    "id": {
      "$ref": "#/$defs/uri"
    },
    "revision": {
      "type": "string",
      "minLength": 1,
      "maxLength": 100
    },
    "published_at": {
      "$ref": "#/$defs/datetime"
    },
    "publisher": {
      "$ref": "#/$defs/publisher"
    },
    "profiles": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/uri"
      },
      "uniqueItems": true
    },
    "subjects": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/subject"
      }
    },
    "claims": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/claim"
      },
      "maxItems": 20000
    },
    "links": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "html": {
          "$ref": "#/$defs/uri"
        },
        "markdown": {
          "$ref": "#/$defs/uri"
        },
        "mcp": {
          "$ref": "#/$defs/uri"
        },
        "terms": {
          "$ref": "#/$defs/uri"
        },
        "corrections": {
          "$ref": "#/$defs/uri"
        }
      }
    },
    "extensions": {
      "$ref": "#/$defs/extensions"
    }
  },
  "$defs": {
    "uri": {
      "type": "string",
      "format": "uri",
      "maxLength": 2000
    },
    "datetime": {
      "type": "string",
      "format": "date-time"
    },
    "identifier": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "scheme",
        "value"
      ],
      "properties": {
        "scheme": {
          "type": "string",
          "pattern": "^[a-z0-9-]{2,30}$"
        },
        "value": {
          "type": "string",
          "minLength": 1,
          "maxLength": 100
        }
      }
    },
    "publisher": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name",
        "role"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/uri"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        },
        "role": {
          "enum": [
            "first_party",
            "aggregator",
            "related_party",
            "reviewer"
          ]
        },
        "domain": {
          "type": "string",
          "pattern": "^[a-z0-9.-]+\\.[a-z]{2,}$"
        },
        "identifiers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/identifier"
          }
        },
        "related_to": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/uri"
          },
          "description": "Organisations the publisher is related to (conflict-of-interest disclosure)."
        },
        "contact": {
          "type": "string",
          "maxLength": 300
        }
      }
    },
    "subject": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "name"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/uri"
        },
        "type": {
          "type": "string",
          "maxLength": 200
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        },
        "url": {
          "$ref": "#/$defs/uri"
        },
        "identifiers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/identifier"
          }
        }
      }
    },
    "money": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "amount",
        "currency"
      ],
      "properties": {
        "type": {
          "const": "money"
        },
        "amount": {
          "type": "string",
          "pattern": "^(0|[1-9][0-9]{0,11})\\.[0-9]{2}$"
        },
        "currency": {
          "type": "string",
          "pattern": "^[A-Z]{3}$"
        },
        "vat_included": {
          "type": "boolean"
        },
        "bound": {
          "enum": [
            "exact",
            "minimum"
          ],
          "description": "minimum = the source states a starting amount (from 10 000); the exact amount depends on details not captured in scope. Default exact."
        }
      }
    },
    "quantity": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "value",
        "unit"
      ],
      "properties": {
        "type": {
          "const": "quantity"
        },
        "value": {
          "type": "string",
          "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,6})?$"
        },
        "unit": {
          "type": "string",
          "minLength": 1,
          "maxLength": 20
        }
      }
    },
    "boolean": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "value"
      ],
      "properties": {
        "type": {
          "const": "boolean"
        },
        "value": {
          "type": "boolean"
        }
      }
    },
    "text": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "value"
      ],
      "properties": {
        "type": {
          "const": "text"
        },
        "value": {
          "type": "string",
          "minLength": 1,
          "maxLength": 2000
        },
        "lang": {
          "type": "string",
          "pattern": "^[a-z]{2}(-[A-Z]{2})?$"
        }
      }
    },
    "enum": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "value"
      ],
      "properties": {
        "type": {
          "const": "enum"
        },
        "value": {
          "type": "string",
          "pattern": "^[a-z0-9_]{1,60}$"
        }
      }
    },
    "enum_set": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "values"
      ],
      "properties": {
        "type": {
          "const": "enum_set"
        },
        "values": {
          "type": "array",
          "items": {
            "type": "string",
            "pattern": "^[a-z0-9_]{1,60}$"
          },
          "uniqueItems": true
        }
      }
    },
    "organization": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "name"
      ],
      "properties": {
        "type": {
          "const": "organization"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        },
        "identifiers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/identifier"
          }
        },
        "url": {
          "$ref": "#/$defs/uri"
        }
      }
    },
    "place": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "type",
        "name"
      ],
      "properties": {
        "type": {
          "const": "place"
        },
        "name": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        },
        "address": {
          "type": "string",
          "maxLength": 500
        },
        "country": {
          "type": "string",
          "pattern": "^[A-Z]{2}$"
        },
        "geo": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "lat",
            "lon"
          ],
          "properties": {
            "lat": {
              "type": "number",
              "minimum": -90,
              "maximum": 90
            },
            "lon": {
              "type": "number",
              "minimum": -180,
              "maximum": 180
            }
          }
        },
        "opening_hours": {
          "type": "string",
          "maxLength": 300,
          "description": "schema.org openingHours syntax, e.g. Mo-Fr 08:00-18:00"
        }
      }
    },
    "value": {
      "oneOf": [
        {
          "$ref": "#/$defs/money"
        },
        {
          "$ref": "#/$defs/quantity"
        },
        {
          "$ref": "#/$defs/boolean"
        },
        {
          "$ref": "#/$defs/text"
        },
        {
          "$ref": "#/$defs/enum"
        },
        {
          "$ref": "#/$defs/enum_set"
        },
        {
          "$ref": "#/$defs/organization"
        },
        {
          "$ref": "#/$defs/place"
        }
      ]
    },
    "evidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "url",
        "observed_at"
      ],
      "properties": {
        "url": {
          "$ref": "#/$defs/uri"
        },
        "observed_at": {
          "$ref": "#/$defs/datetime"
        },
        "kind": {
          "enum": [
            "webpage",
            "document",
            "registry",
            "contract",
            "system",
            "statement"
          ]
        },
        "issuer": {
          "type": "string",
          "maxLength": 300
        },
        "quote": {
          "type": "string",
          "maxLength": 600,
          "description": "Verbatim excerpt of the evidence that states the value."
        },
        "digest": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        }
      }
    },
    "attestation": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "issuer",
        "method",
        "claim_digest",
        "issued_at",
        "expires_at"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/uri"
        },
        "issuer": {
          "$ref": "#/$defs/uri"
        },
        "issuer_relation": {
          "enum": [
            "independent",
            "related_party",
            "first_party"
          ]
        },
        "method": {
          "type": "string",
          "minLength": 1,
          "maxLength": 300
        },
        "claim_digest": {
          "type": "string",
          "pattern": "^sha256:[0-9a-f]{64}$"
        },
        "issued_at": {
          "$ref": "#/$defs/datetime"
        },
        "expires_at": {
          "$ref": "#/$defs/datetime"
        },
        "status_url": {
          "$ref": "#/$defs/uri"
        },
        "credential_url": {
          "$ref": "#/$defs/uri"
        }
      }
    },
    "dispute": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "since"
      ],
      "properties": {
        "since": {
          "$ref": "#/$defs/datetime"
        },
        "conflicting_claims": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/uri"
          }
        },
        "note": {
          "type": "string",
          "maxLength": 1000
        }
      }
    },
    "extensions": {
      "type": "object",
      "description": "Keys are absolute URIs. Each value is {\"affects_use\": boolean, \"value\": any}.",
      "propertyNames": {
        "format": "uri"
      },
      "additionalProperties": {
        "type": "object",
        "required": [
          "affects_use",
          "value"
        ],
        "properties": {
          "affects_use": {
            "type": "boolean"
          },
          "value": {}
        }
      }
    },
    "claim": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "id",
        "subject",
        "property",
        "knowledge_state",
        "scope",
        "assertion_basis",
        "valid_from",
        "valid_until"
      ],
      "properties": {
        "id": {
          "$ref": "#/$defs/uri"
        },
        "revision": {
          "type": "string",
          "maxLength": 100
        },
        "subject": {
          "$ref": "#/$defs/uri"
        },
        "property": {
          "$ref": "#/$defs/uri"
        },
        "knowledge_state": {
          "enum": [
            "known",
            "unknown",
            "not_applicable"
          ]
        },
        "value": {
          "$ref": "#/$defs/value"
        },
        "scope": {
          "type": "object",
          "maxProperties": 30,
          "additionalProperties": {
            "type": "string",
            "minLength": 1,
            "maxLength": 300
          }
        },
        "assertion_basis": {
          "enum": [
            "publisher_asserted",
            "source_correlated",
            "independently_reviewed"
          ]
        },
        "evidence": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/evidence"
          },
          "maxItems": 20
        },
        "valid_from": {
          "$ref": "#/$defs/datetime"
        },
        "valid_until": {
          "$ref": "#/$defs/datetime"
        },
        "note": {
          "type": "string",
          "maxLength": 1000
        },
        "dispute": {
          "$ref": "#/$defs/dispute"
        },
        "attestations": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/attestation"
          },
          "maxItems": 20
        },
        "extensions": {
          "$ref": "#/$defs/extensions"
        }
      },
      "allOf": [
        {
          "if": {
            "properties": {
              "knowledge_state": {
                "const": "known"
              }
            }
          },
          "then": {
            "required": [
              "value",
              "evidence"
            ],
            "properties": {
              "evidence": {
                "minItems": 1
              }
            }
          },
          "else": {
            "not": {
              "required": [
                "value"
              ]
            }
          }
        }
      ]
    }
  }
}