{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://tekcapitol.com/schema/write-intent/v1/write-intent.v1.json",
  "title": "TC Protect Write Intent v1",
  "description": "Metadata-only package the orchestrator emits to check_write before a mutating side effect. TekCapitol does not query the system of record.",
  "type": "object",
  "additionalProperties": false,
  "required": ["schemaVersion", "system", "objectType", "objectRef", "intendedChanges"],
  "properties": {
    "schemaVersion": {
      "const": "write_intent.v1"
    },
    "system": {
      "type": "string",
      "description": "System of record id, e.g. Salesforce, SAP, Snowflake."
    },
    "objectType": {
      "type": "string",
      "description": "Object / entity type, e.g. Opportunity, Contract."
    },
    "objectRef": {
      "type": "string",
      "description": "Record id in the system of record."
    },
    "intendedChanges": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["field", "newValue"],
        "properties": {
          "field": { "type": "string" },
          "newValue": {}
        }
      }
    },
    "authority": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "value": {},
        "fields": { "type": "object" },
        "bindings": {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "field": { "type": "string" },
              "agentValue": {},
              "authorityValue": {}
            }
          }
        },
        "source": {
          "type": "string",
          "description": "Independent SoR id. Prefer billing_sor / crm_entitlement, not prompt or agent_spec."
        },
        "found": { "type": "boolean" },
        "checkedAt": {
          "type": "string",
          "description": "ISO-8601 time the orchestrator read authority (not the Salesforce SystemModstamp alone)."
        },
        "maxAgeMs": {
          "type": "integer",
          "minimum": 0,
          "description": "Freshness window for checkedAt."
        },
        "stalePolicy": {
          "type": "string",
          "enum": ["warn", "pause", "block"],
          "default": "warn"
        }
      }
    },
    "freshness": {
      "type": "object",
      "additionalProperties": false,
      "description": "Optional lightweight SoR verification signals emitted by the orchestrator.",
      "properties": {
        "recordVersion": {
          "type": "string",
          "description": "e.g. Salesforce SystemModstamp or row version."
        },
        "stampType": {
          "type": "string",
          "description": "e.g. SystemModstamp, hash, etag."
        },
        "hash": {
          "type": "string",
          "description": "Optional hash of critical fields known to the orchestrator."
        }
      }
    },
    "workflowId": { "type": "string" },
    "agentIdentity": { "type": "string" },
    "runId": { "type": "string" },
    "policyTags": {
      "type": "array",
      "items": { "type": "string" }
    },
    "requireApproval": {
      "type": "boolean",
      "description": "If true, check_write returns decision=pause (HITL) even when values match."
    },
    "idempotencyKey": { "type": "string" }
  }
}
