{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://governedai.ai/schemas/counterparty_registry.schema.json",
  "title": "Counterparty Registry Entry",
  "description": "A single entry in the internal counterparty registry. The schema is published; specific entries are TIER_2_NDA or higher and are never public.",
  "type": "object",
  "required": [
    "counterparty_id",
    "schema_version",
    "registered_at",
    "organization",
    "jurisdiction",
    "engagement_type",
    "nda_status",
    "named_contacts",
    "disclosure_tier"
  ],
  "additionalProperties": false,
  "properties": {
    "counterparty_id": {
      "type": "string",
      "pattern": "^CP-[A-Z0-9]{8}$",
      "description": "Internal opaque identifier; never derived from organization name"
    },
    "schema_version": {
      "type": "string",
      "const": "0.1.0"
    },
    "registered_at": {
      "type": "string",
      "format": "date-time"
    },
    "organization": {
      "type": "object",
      "required": ["legal_entity_name", "country_of_incorporation"],
      "properties": {
        "legal_entity_name": { "type": "string" },
        "country_of_incorporation": { "type": "string", "pattern": "^[A-Z]{2}$" },
        "regulatory_designation": { "type": "string" }
      },
      "additionalProperties": false
    },
    "jurisdiction": {
      "type": "object",
      "required": ["primary"],
      "properties": {
        "primary": { "type": "string" },
        "additional": { "type": "array", "items": { "type": "string" } }
      },
      "additionalProperties": false
    },
    "engagement_type": {
      "type": "string",
      "enum": ["evaluator", "partner", "investor_diligence", "regulator_inquiry", "counsel_to_counsel"]
    },
    "nda_status": {
      "type": "object",
      "required": ["status", "as_of"],
      "properties": {
        "status": {
          "type": "string",
          "enum": ["none", "requested", "executed", "expired", "declined"]
        },
        "as_of": { "type": "string", "format": "date-time" },
        "nda_reference": { "type": "string" },
        "expires_at": { "type": "string", "format": "date-time" }
      },
      "additionalProperties": false
    },
    "named_contacts": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": ["name", "role"],
        "properties": {
          "name": { "type": "string" },
          "role": { "type": "string" },
          "is_counsel": { "type": "boolean", "default": false },
          "is_technical_evaluator": { "type": "boolean", "default": false }
        },
        "additionalProperties": false
      }
    },
    "disclosure_tier": {
      "type": "string",
      "enum": ["TIER_2_NDA", "TIER_3_INTERNAL_ONLY"],
      "description": "Counterparty registry entries are never public"
    },
    "active_engagements": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["engagement_id", "scope", "status"],
        "properties": {
          "engagement_id": { "type": "string" },
          "scope": { "type": "string" },
          "status": {
            "type": "string",
            "enum": ["scoping", "active", "paused", "closed"]
          },
          "diligence_room_provisioned": { "type": "boolean", "default": false }
        }
      }
    },
    "audit_log": {
      "type": "array",
      "items": {
        "type": "object",
        "required": ["timestamp", "action"],
        "properties": {
          "timestamp": { "type": "string", "format": "date-time" },
          "action": { "type": "string" },
          "actor": { "type": "string" }
        }
      },
      "description": "Append-only log; entries never deleted"
    }
  }
}
