{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.nextedge.consulting/schemas/open-control-gate-v1.json",
  "title": "NextEdge Open Control-Gate Specification v1.0",
  "description": "Canonical schema for deterministic physical-to-digital control gates, system-of-record state transitions, bounded AI agent guardrails, and dual-market US (USD $) + India (INR ₹) statutory reconciliation.",
  "type": "object",
  "required": [
    "gateId",
    "industry",
    "businessFunction",
    "systemOfRecord",
    "triggerEvent",
    "deterministicPredicates",
    "quarantineState",
    "boundedAiRole",
    "dualMarketCompliance"
  ],
  "properties": {
    "gateId": {
      "type": "string",
      "pattern": "^[LMHPOREF][0-9]{4}-GATE-[0-9]{2}$",
      "description": "Unique deterministic control-gate identifier bound to the 8,000-article NextEdge catalog."
    },
    "industry": {
      "type": "string",
      "enum": [
        "logistics-and-supply-chain",
        "manufacturing",
        "healthcare",
        "pharma-and-life-sciences",
        "oil-and-gas",
        "retail-and-ecommerce",
        "epc-and-construction",
        "food-and-beverage"
      ]
    },
    "businessFunction": {
      "type": "string",
      "minLength": 3
    },
    "systemOfRecord": {
      "type": "object",
      "required": ["primarySystem", "telemetryOrEdgeSource", "financialSubledger"],
      "properties": {
        "primarySystem": { "type": "string" },
        "telemetryOrEdgeSource": { "type": "string" },
        "financialSubledger": { "type": "string" },
        "idempotencyKeyFormat": { "type": "string" }
      }
    },
    "triggerEvent": {
      "type": "string",
      "description": "Physical scan, PLC/SCADA telemetry threshold, EDI/FHIR/API payload, or commercial settlement event that invokes the gate."
    },
    "deterministicPredicates": {
      "type": "array",
      "minItems": 2,
      "items": {
        "type": "object",
        "required": ["field", "operator", "toleranceOrRule", "failureAction"],
        "properties": {
          "field": { "type": "string" },
          "operator": { "type": "string", "enum": ["EQ", "LTE", "GTE", "WITHIN_TOLERANCE", "SCHEMA_VALID", "DUAL_ATTESTED"] },
          "toleranceOrRule": { "type": "string" },
          "failureAction": { "type": "string", "enum": ["HARD_BLOCK", "QUARANTINE_HOLD", "SUSPENSE_SUBLEDGER", "SUPERVISOR_ESCALATION"] }
        }
      }
    },
    "quarantineState": {
      "type": "object",
      "required": ["holdQueue", "releaseAuthorityRole", "requiredEvidencePacket", "slaMinutes"],
      "properties": {
        "holdQueue": { "type": "string" },
        "releaseAuthorityRole": { "type": "string" },
        "requiredEvidencePacket": { "type": "array", "items": { "type": "string" } },
        "slaMinutes": { "type": "integer", "minimum": 1 }
      }
    },
    "boundedAiRole": {
      "type": "object",
      "required": ["permittedActions", "forbiddenActions"],
      "properties": {
        "permittedActions": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Read-only anomaly clustering, OCR/document packet pre-staging, and root-cause recommendation."
        },
        "forbiddenActions": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Direct GL posting, safety interlock bypass, CoA/batch release sign-off, or tolerance self-modification."
        }
      }
    },
    "dualMarketCompliance": {
      "type": "object",
      "required": ["us", "india"],
      "properties": {
        "us": {
          "type": "object",
          "required": ["currency", "statutoryClauses", "accountingStandard"],
          "properties": {
            "currency": { "const": "USD ($)" },
            "statutoryClauses": { "type": "array", "items": { "type": "string" } },
            "accountingStandard": { "type": "string" }
          }
        },
        "india": {
          "type": "object",
          "required": ["currency", "statutoryClauses", "accountingStandard"],
          "properties": {
            "currency": { "const": "INR (₹)" },
            "statutoryClauses": { "type": "array", "items": { "type": "string" } },
            "accountingStandard": { "type": "string" }
          }
        }
      }
    }
  }
}
