{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://openprivacyprotocol.com/schema/0.1/model.schema.json",
  "title": "OPP privacy model",
  "type": "object",
  "properties": {
    "opp": {
      "type": "string",
      "minLength": 1
    },
    "name": {
      "type": "string",
      "minLength": 1
    },
    "organization": {
      "type": "string",
      "minLength": 1
    },
    "description": {
      "type": "string"
    },
    "catalog": {
      "$ref": "#/$defs/CatalogRef"
    },
    "sources": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Source"
      }
    },
    "concepts": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Concept"
      }
    },
    "identifiers": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Identifier"
      }
    },
    "terms": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Term"
      }
    },
    "rules": {
      "$ref": "#/$defs/Rules"
    },
    "provenance": {
      "$ref": "#/$defs/Provenance"
    },
    "extensions": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/Extension"
      }
    }
  },
  "required": [
    "opp",
    "name",
    "organization",
    "catalog",
    "sources"
  ],
  "additionalProperties": false,
  "$defs": {
    "Sensitivity": {
      "enum": [
        "public",
        "internal",
        "confidential",
        "restricted"
      ]
    },
    "Handling": {
      "enum": [
        "allow",
        "generalize",
        "pseudonymize",
        "redact",
        "block"
      ]
    },
    "Destination": {
      "enum": [
        "internal",
        "partner",
        "external_ai",
        "public"
      ]
    },
    "Action": {
      "enum": [
        "allow",
        "generalize",
        "pseudonymize",
        "redact",
        "block",
        "review",
        "handling"
      ]
    },
    "Status": {
      "enum": [
        "proposed",
        "certified"
      ]
    },
    "CatalogRef": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "version": {
          "type": "string",
          "minLength": 1
        },
        "url": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "name",
        "version"
      ],
      "additionalProperties": false
    },
    "Extension": {
      "type": "object",
      "properties": {
        "vendor_name": {
          "type": "string",
          "minLength": 1
        },
        "data": {
          "type": "object"
        }
      },
      "required": [
        "vendor_name",
        "data"
      ],
      "additionalProperties": false
    },
    "Evidence": {
      "type": "object",
      "properties": {
        "kind": {
          "enum": [
            "name",
            "values",
            "detector",
            "person"
          ]
        },
        "detail": {
          "type": "string",
          "minLength": 1
        },
        "share": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "sampled": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "kind",
        "detail"
      ],
      "additionalProperties": false
    },
    "Classification": {
      "type": "object",
      "properties": {
        "class": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(\\.[a-z0-9_]+)*$"
        },
        "confidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "status": {
          "$ref": "#/$defs/Status"
        },
        "evidence": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Evidence"
          }
        }
      },
      "required": [
        "class",
        "confidence",
        "status"
      ],
      "additionalProperties": false
    },
    "Field": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "datatype": {
          "type": "string"
        },
        "classes": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Classification"
          }
        },
        "sensitivity": {
          "$ref": "#/$defs/Sensitivity"
        },
        "handling": {
          "$ref": "#/$defs/Handling"
        },
        "identifier": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(\\.[a-z0-9_]+)*$"
        },
        "ossie_field": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "name"
      ],
      "additionalProperties": false
    },
    "Dataset": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "type": {
          "enum": [
            "table",
            "file",
            "document",
            "page"
          ]
        },
        "description": {
          "type": "string"
        },
        "fields": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Field"
          }
        },
        "topics": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Classification"
          }
        },
        "sensitivity": {
          "$ref": "#/$defs/Sensitivity"
        }
      },
      "required": [
        "name",
        "type"
      ],
      "additionalProperties": false
    },
    "OssieRef": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string",
          "minLength": 1
        },
        "url": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "name"
      ],
      "additionalProperties": false
    },
    "Source": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(\\.[a-z0-9_]+)*$"
        },
        "type": {
          "enum": [
            "database",
            "file",
            "document",
            "web",
            "api"
          ]
        },
        "locator": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string"
        },
        "datasets": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Dataset"
          }
        },
        "ossie": {
          "$ref": "#/$defs/OssieRef"
        }
      },
      "required": [
        "id",
        "type",
        "locator",
        "datasets"
      ],
      "additionalProperties": false
    },
    "Concept": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(\\.[a-z0-9_]+)*$"
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string",
          "minLength": 1
        },
        "extends": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(\\.[a-z0-9_]+)*$"
        },
        "sensitivity": {
          "$ref": "#/$defs/Sensitivity"
        },
        "handling": {
          "$ref": "#/$defs/Handling"
        },
        "synonyms": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "cues": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "status": {
          "$ref": "#/$defs/Status"
        }
      },
      "required": [
        "id",
        "label",
        "description",
        "extends",
        "status"
      ],
      "additionalProperties": false
    },
    "Identifier": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(\\.[a-z0-9_]+)*$"
        },
        "label": {
          "type": "string",
          "minLength": 1
        },
        "class": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(\\.[a-z0-9_]+)*$"
        },
        "pattern": {
          "type": "string",
          "minLength": 1
        },
        "keywords": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "status": {
          "$ref": "#/$defs/Status"
        }
      },
      "required": [
        "id",
        "label",
        "class",
        "pattern",
        "status"
      ],
      "additionalProperties": false
    },
    "Term": {
      "type": "object",
      "properties": {
        "term": {
          "type": "string",
          "minLength": 1
        },
        "class": {
          "type": "string",
          "pattern": "^[a-z][a-z0-9_]*(\\.[a-z0-9_]+)*$"
        },
        "status": {
          "$ref": "#/$defs/Status"
        }
      },
      "required": [
        "term",
        "class",
        "status"
      ],
      "additionalProperties": false
    },
    "Rules": {
      "type": "object",
      "properties": {
        "default": {
          "type": "object",
          "propertyNames": {
            "enum": [
              "public",
              "internal",
              "confidential",
              "restricted"
            ]
          },
          "additionalProperties": {
            "type": "object",
            "propertyNames": {
              "enum": [
                "internal",
                "partner",
                "external_ai",
                "public"
              ]
            },
            "additionalProperties": {
              "$ref": "#/$defs/Action"
            }
          }
        },
        "overrides": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "target": {
                "type": "string",
                "minLength": 1
              },
              "destination": {
                "$ref": "#/$defs/Destination"
              },
              "action": {
                "$ref": "#/$defs/Action"
              },
              "reason": {
                "type": "string"
              }
            },
            "required": [
              "target",
              "destination",
              "action"
            ],
            "additionalProperties": false
          }
        }
      },
      "required": [],
      "additionalProperties": false
    },
    "Provenance": {
      "type": "object",
      "properties": {
        "generator": {
          "type": "string",
          "minLength": 1
        },
        "generated_at": {
          "type": "string",
          "format": "date-time"
        },
        "reviewed_by": {
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          }
        },
        "notes": {
          "type": "string"
        }
      },
      "required": [],
      "additionalProperties": false
    }
  }
}
