{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://paloframework.org/schemas/palo-data-disclosure-contract.schema.json",
  "title": "PALO Data Disclosure Contract",
  "description": "Signed, purpose-bound contract governing data read scope, information egress, provider and region, redaction, tracing and retention.",
  "type": "object",
  "required": ["format", "schemaVersion", "disclosureContractId", "tenantId", "subject", "purpose", "lawfulBasis", "dataScope", "egressPolicy", "destinationPolicy", "tracePolicy", "outputPolicy", "boundFitnessDecision", "issuedAt", "expiresAt", "status", "keyId", "algorithm", "signature"],
  "properties": {
    "format": { "const": "palo-data-disclosure-contract" },
    "schemaVersion": { "const": "1.0.0" },
    "disclosureContractId": { "type": "string", "pattern": "^disclosure-[a-f0-9-]{36}$" },
    "tenantId": { "type": "string", "minLength": 1, "maxLength": 128 },
    "subject": { "$ref": "#/$defs/subject" },
    "purpose": { "type": "string", "minLength": 1, "maxLength": 300 },
    "lawfulBasis": { "enum": ["consent", "contract", "legal-obligation", "vital-interests", "public-task", "legitimate-interests", "not-applicable", "pending-review"] },
    "dataScope": {
      "type": "object",
      "required": ["sourceRefs", "allowedFields", "deniedFields", "maxRowsRead"],
      "properties": {
        "sourceRefs": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1, "maxLength": 1000 } },
        "allowedFields": { "type": "array", "uniqueItems": true, "maxItems": 1000, "items": { "type": "string", "minLength": 1, "maxLength": 500 } },
        "deniedFields": { "type": "array", "uniqueItems": true, "maxItems": 1000, "items": { "type": "string", "minLength": 1, "maxLength": 500 } },
        "maxRowsRead": { "type": "integer", "minimum": 0, "maximum": 10000000 }
      },
      "additionalProperties": false
    },
    "egressPolicy": {
      "type": "object",
      "required": ["mode", "maxRows", "allowedFields", "prohibitedCategories", "requiredRedactions"],
      "properties": {
        "mode": { "enum": ["zero-row", "aggregated", "row-level"] },
        "maxRows": { "type": "integer", "minimum": 0, "maximum": 1000000 },
        "allowedFields": { "type": "array", "uniqueItems": true, "maxItems": 1000, "items": { "type": "string", "minLength": 1, "maxLength": 500 } },
        "prohibitedCategories": { "type": "array", "uniqueItems": true, "maxItems": 100, "items": { "type": "string", "minLength": 1, "maxLength": 200 } },
        "requiredRedactions": { "type": "array", "uniqueItems": true, "maxItems": 100, "items": { "type": "string", "minLength": 1, "maxLength": 200 } },
        "minimumAggregationGroupSize": { "type": "integer", "minimum": 2, "maximum": 1000000 }
      },
      "allOf": [
        {
          "if": { "properties": { "mode": { "const": "zero-row" } }, "required": ["mode"] },
          "then": { "properties": { "maxRows": { "type": "integer", "const": 0 }, "allowedFields": { "type": "array", "maxItems": 0 } } }
        },
        {
          "if": { "properties": { "mode": { "const": "aggregated" } }, "required": ["mode"] },
          "then": { "properties": { "minimumAggregationGroupSize": { "type": "integer" } }, "required": ["minimumAggregationGroupSize"] }
        }
      ],
      "additionalProperties": false
    },
    "destinationPolicy": {
      "type": "object",
      "required": ["allowedRecipients", "allowedProviders", "allowedModels", "allowedRegions", "allowedEndpointHosts"],
      "properties": {
        "allowedRecipients": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1, "maxLength": 500 } },
        "allowedProviders": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1, "maxLength": 200 } },
        "allowedModels": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1, "maxLength": 300 } },
        "allowedRegions": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "minLength": 1, "maxLength": 100 } },
        "allowedEndpointHosts": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "type": "string", "pattern": "^[a-z0-9.-]+$", "maxLength": 253 } }
      },
      "additionalProperties": false
    },
    "tracePolicy": {
      "type": "object",
      "required": ["allowedModes", "maxRetentionSeconds"],
      "properties": {
        "allowedModes": { "type": "array", "minItems": 1, "uniqueItems": true, "items": { "enum": ["disabled", "metadata-only", "redacted-payload"] } },
        "maxRetentionSeconds": { "type": "integer", "minimum": 0, "maximum": 31536000 }
      },
      "additionalProperties": false
    },
    "outputPolicy": {
      "type": "object",
      "required": ["exportAllowed"],
      "properties": {
        "exportAllowed": { "type": "boolean" },
        "schemaDigest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" }
      },
      "additionalProperties": false
    },
    "boundFitnessDecision": {
      "type": "object",
      "required": ["decisionId", "decisionDigest"],
      "properties": {
        "decisionId": { "type": "string", "pattern": "^fitness-decision-[a-f0-9-]{36}$" },
        "decisionDigest": { "type": "string", "pattern": "^sha256:[a-f0-9]{64}$" }
      },
      "additionalProperties": false
    },
    "approvedBy": { "type": "string", "minLength": 1, "maxLength": 500 },
    "issuedAt": { "type": "string", "format": "date-time" },
    "expiresAt": { "type": "string", "format": "date-time" },
    "status": { "enum": ["active", "revoked"] },
    "keyId": { "type": "string", "pattern": "^key-[a-zA-Z0-9._-]{3,100}$" },
    "algorithm": { "const": "HMAC-SHA256" },
    "signature": { "type": "string", "pattern": "^hmac-sha256:[a-f0-9]{64}$" }
  },
  "$defs": {
    "subject": {
      "type": "object",
      "required": ["type", "id"],
      "properties": {
        "type": { "enum": ["dataset", "data-product", "model", "ai-system", "agent", "tool", "access-entitlement", "other"] },
        "id": { "type": "string", "minLength": 1, "maxLength": 1000 }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
