{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "gno://schemas/capture-receipt@1.0",
  "title": "GNO Capture Receipt",
  "description": "Shared receipt returned by capture surfaces after a write/open decision.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "uri",
    "collection",
    "relPath",
    "created",
    "openedExisting",
    "createdWithSuffix",
    "contentHash",
    "source",
    "tags",
    "sync",
    "embed",
    "collisionPolicyResult"
  ],
  "properties": {
    "schemaVersion": {
      "const": "1.0",
      "description": "Present on browser-clipper HTTP responses."
    },
    "uri": {
      "type": "string",
      "description": "GNO URI for the captured note.",
      "pattern": "^gno://[^/]+/.+"
    },
    "docid": {
      "type": "string",
      "description": "Document id when sync has resolved it."
    },
    "collection": {
      "type": "string",
      "description": "Target collection name."
    },
    "relPath": {
      "type": "string",
      "description": "Relative path within the collection."
    },
    "absPath": {
      "type": "string",
      "description": "Absolute path when the local surface exposes it."
    },
    "serverInstanceId": {
      "type": "string"
    },
    "created": {
      "type": "boolean",
      "description": "True when a new file was written."
    },
    "openedExisting": {
      "type": "boolean",
      "description": "True when collision policy selected an existing file."
    },
    "createdWithSuffix": {
      "type": "boolean",
      "description": "True when a suffixed path was created after collision."
    },
    "overwritten": {
      "type": "boolean",
      "description": "Legacy compatibility flag for overwrite-capable surfaces."
    },
    "contentHash": {
      "type": "string",
      "description": "SHA-256 hash of normalized capture body content.",
      "pattern": "^[a-f0-9]{64}$"
    },
    "source": {
      "type": "object",
      "additionalProperties": false,
      "required": ["kind", "capturedAt"],
      "properties": {
        "kind": {
          "type": "string",
          "enum": [
            "direct",
            "web",
            "email",
            "meeting",
            "chat",
            "file",
            "api",
            "unknown"
          ]
        },
        "title": { "type": "string" },
        "url": { "type": "string", "format": "uri" },
        "uri": { "type": "string" },
        "docid": { "type": "string" },
        "mime": { "type": "string" },
        "ext": { "type": "string" },
        "author": { "type": "string" },
        "canonicalUrl": { "type": "string", "format": "uri" },
        "site": { "type": "string" },
        "publishedAt": {
          "oneOf": [
            { "type": "string", "format": "date" },
            { "type": "string", "format": "date-time" }
          ]
        },
        "observedAt": { "type": "string", "format": "date-time" },
        "capturedAt": { "type": "string", "format": "date-time" },
        "externalId": { "type": "string" },
        "browserClip": {
          "$ref": "gno://schemas/browser-clip@1.0#/definitions/provenance"
        }
      }
    },
    "tags": {
      "type": "array",
      "items": { "type": "string" }
    },
    "sync": {
      "$ref": "#/definitions/indexStatus"
    },
    "embed": {
      "$ref": "#/definitions/indexStatus"
    },
    "collisionPolicyResult": {
      "type": "string",
      "enum": [
        "created",
        "opened_existing",
        "created_with_suffix",
        "overwritten",
        "conflict"
      ]
    }
  },
  "definitions": {
    "indexStatus": {
      "type": "object",
      "additionalProperties": false,
      "required": ["status"],
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "not_requested",
            "pending",
            "running",
            "completed",
            "skipped",
            "failed",
            "unknown"
          ]
        },
        "jobId": {
          "type": ["string", "null"]
        },
        "reason": {
          "type": "string"
        },
        "error": {
          "type": "string"
        }
      }
    }
  }
}
