{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://delib.mashbean.net/schemas/delib-pocket-polis/v1.json",
  "title": "Delib Pocket Polis export bundle v1",
  "description": "A local, participant-aware handoff built from Pocket Polis statements.csv and votes.csv.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schema", "kind", "exportedAt", "source", "summary", "consistency", "statements", "votes", "dataCard"],
  "properties": {
    "schema": { "const": "https://delib.mashbean.net/schemas/delib-pocket-polis/v1.json" },
    "kind": { "const": "pocket-polis-export" },
    "exportedAt": { "type": "string", "format": "date-time" },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": ["tool", "origin", "conversationId", "reportUrl", "title", "description", "importedFiles", "persistedByDelib"],
      "properties": {
        "tool": { "const": "Pocket Polis" },
        "origin": { "type": "string", "format": "uri", "pattern": "^https://" },
        "conversationId": { "type": "string", "pattern": "^[a-z0-9]{10}$" },
        "reportUrl": { "type": "string", "format": "uri", "pattern": "^https://" },
        "title": { "type": "string", "minLength": 1, "maxLength": 120 },
        "description": { "type": "string", "maxLength": 2000 },
        "importedFiles": {
          "type": "array",
          "minItems": 2,
          "maxItems": 2,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["role", "name", "size", "sha256"],
            "properties": {
              "role": { "enum": ["statements", "votes"] },
              "name": { "type": "string", "minLength": 1, "maxLength": 180 },
              "size": { "type": "integer", "minimum": 1 },
              "sha256": { "type": "string", "pattern": "^[a-f0-9]{64}$" }
            }
          }
        },
        "persistedByDelib": { "const": false }
      }
    },
    "summary": {
      "type": "object",
      "additionalProperties": false,
      "required": ["statements", "approvedStatements", "seedStatements", "participantSubmittedStatements", "participants", "votes", "coverage"],
      "properties": {
        "statements": { "type": "integer", "minimum": 1 },
        "approvedStatements": { "type": "integer", "minimum": 0 },
        "seedStatements": { "type": "integer", "minimum": 0 },
        "participantSubmittedStatements": { "type": "integer", "minimum": 0 },
        "participants": { "type": "integer", "minimum": 0, "description": "Unique pseudonymous participants with at least one vote in votes.csv; this can be lower than the conversation's opened-session count." },
        "votes": { "type": "integer", "minimum": 0 },
        "coverage": { "type": "number", "minimum": 0, "maximum": 1 }
      }
    },
    "consistency": {
      "type": "object",
      "additionalProperties": false,
      "required": ["countMatches", "mismatchedStatements"],
      "properties": {
        "countMatches": { "type": "boolean" },
        "mismatchedStatements": {
          "type": "array",
          "uniqueItems": true,
          "items": { "type": "integer", "minimum": 1 }
        }
      }
    },
    "statements": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["statementId", "text", "status", "isSeed", "agrees", "disagrees", "passes", "createdAt"],
        "properties": {
          "statementId": { "type": "integer", "minimum": 1 },
          "text": { "type": "string", "minLength": 1, "maxLength": 280 },
          "status": { "enum": ["approved", "pending", "rejected"] },
          "isSeed": { "type": "boolean" },
          "agrees": { "type": "integer", "minimum": 0 },
          "disagrees": { "type": "integer", "minimum": 0 },
          "passes": { "type": "integer", "minimum": 0 },
          "createdAt": { "type": "string", "format": "date-time" }
        }
      }
    },
    "votes": {
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["participant", "statementId", "value", "updatedAt"],
        "properties": {
          "participant": { "type": "string", "pattern": "^p[1-9][0-9]{0,8}$" },
          "statementId": { "type": "integer", "minimum": 1 },
          "value": { "enum": [-1, 0, 1] },
          "updatedAt": { "type": "string", "format": "date-time" }
        }
      }
    },
    "dataCard": {
      "type": "object",
      "additionalProperties": false,
      "required": ["containsParticipantData", "containsDirectIdentifiers", "containsParticipantFreeText", "containsPseudonymousLinkage", "publicationStatus", "storedByDelib", "limitations"],
      "properties": {
        "containsParticipantData": { "const": true },
        "containsDirectIdentifiers": { "const": false },
        "containsParticipantFreeText": { "const": true },
        "containsPseudonymousLinkage": { "const": true },
        "publicationStatus": { "const": "local-private-export" },
        "storedByDelib": { "const": false },
        "limitations": {
          "type": "array",
          "minItems": 3,
          "items": { "type": "string", "minLength": 1 }
        }
      }
    }
  }
}
