{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "gno://schemas/backlinks@1.0",
  "title": "GNO Backlinks",
  "description": "List of documents linking to a target document",
  "type": "object",
  "required": ["backlinks", "meta"],
  "properties": {
    "backlinks": {
      "type": "array",
      "description": "List of documents linking to this one",
      "items": {
        "oneOf": [
          {
            "type": "object",
            "required": ["sourceDocid", "sourceUri", "startLine", "startCol"],
            "additionalProperties": false,
            "properties": {
              "sourceDocid": {
                "type": "string",
                "description": "Source document ID"
              },
              "sourceUri": {
                "type": "string",
                "description": "Source document URI"
              },
              "sourceTitle": {
                "type": "string",
                "description": "Source document title"
              },
              "linkText": {
                "type": "string",
                "description": "Link display text"
              },
              "startLine": {
                "type": "integer",
                "description": "1-based line number in source",
                "minimum": 1
              },
              "startCol": {
                "type": "integer",
                "description": "1-based column in source",
                "minimum": 1
              }
            }
          },
          {
            "type": "object",
            "required": [
              "sourceDocid",
              "sourceUri",
              "edgeType",
              "confidence",
              "edgeSource"
            ],
            "additionalProperties": false,
            "properties": {
              "sourceDocid": {
                "type": "string",
                "description": "Source document ID"
              },
              "sourceUri": {
                "type": "string",
                "description": "Source document URI"
              },
              "sourceTitle": {
                "type": "string",
                "description": "Source document title"
              },
              "edgeType": {
                "type": "string",
                "description": "Semantic relationship type"
              },
              "relationType": {
                "type": "string",
                "description": "Alias of edgeType"
              },
              "confidence": {
                "type": "string",
                "enum": ["parsed", "configured", "manual", "inferred"]
              },
              "edgeSource": {
                "type": "string",
                "enum": ["wikilink", "markdown-link", "frontmatter-relation"]
              }
            }
          }
        ]
      }
    },
    "meta": {
      "type": "object",
      "required": ["docid", "totalBacklinks"],
      "properties": {
        "docid": {
          "type": "string",
          "description": "Target document ID"
        },
        "uri": {
          "type": "string",
          "description": "Target document URI"
        },
        "title": {
          "type": "string",
          "description": "Target document title"
        },
        "totalBacklinks": {
          "type": "integer",
          "description": "Total number of backlinks",
          "minimum": 0
        },
        "collection": {
          "type": "string",
          "description": "Collection filter applied"
        },
        "edgeTypeFilter": {
          "type": "string",
          "description": "Semantic edge-type filter applied"
        },
        "relationFilter": {
          "type": "string",
          "description": "Semantic relation filter applied"
        },
        "semantic": {
          "type": "boolean",
          "description": "Whether backlinks came from the semantic edge layer"
        }
      }
    }
  }
}
