{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://gno.sh/schemas/collection-egress-check.schema.json",
  "title": "Collection egress check and explanation",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "schemaVersion",
    "mode",
    "allowedCollections",
    "omittedCollections",
    "disclosure",
    "lineage",
    "decision",
    "remediation"
  ],
  "properties": {
    "schemaVersion": { "const": "1.0" },
    "mode": { "enum": ["complete", "partial", "denied"] },
    "allowedCollections": {
      "type": "array",
      "items": { "type": "string" },
      "uniqueItems": true
    },
    "omittedCollections": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["collection", "reason"],
        "properties": {
          "collection": { "type": "string" },
          "reason": { "type": "string" }
        }
      }
    },
    "disclosure": {
      "oneOf": [
        { "type": "null" },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["code", "omittedCount", "omittedCollections"],
          "properties": {
            "code": { "const": "EGRESS_PARTIAL_RESULT" },
            "omittedCount": { "type": "integer", "minimum": 1 },
            "omittedCollections": {
              "type": "array",
              "items": { "type": "string" },
              "minItems": 1,
              "uniqueItems": true
            }
          }
        }
      ]
    },
    "lineage": {
      "type": "object",
      "required": ["effectivePolicy", "digest", "sources"],
      "properties": {
        "effectivePolicy": { "enum": ["local_only", "lan", "remote"] },
        "digest": { "type": "string", "pattern": "^[a-f0-9]{64}$" },
        "sources": { "type": "array", "minItems": 1 }
      }
    },
    "decision": {
      "type": "object",
      "required": ["allowed", "code", "reason", "audit"],
      "properties": {
        "allowed": { "type": "boolean" },
        "code": { "enum": ["EGRESS_ALLOWED", "EGRESS_DENIED"] },
        "reason": { "type": "string" },
        "audit": { "type": "object" }
      }
    },
    "remediation": {
      "oneOf": [
        { "type": "null" },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["code", "message"],
          "properties": {
            "code": { "type": "string" },
            "message": { "type": "string", "minLength": 1 }
          }
        }
      ]
    }
  }
}
