{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.anguskit.com/schema/anguscopilot-knowledge/1.0.0-alpha/source.json",
  "title": "Knowledge Source",
  "description": "知识库数据源配置（与 §14.4.4 对齐）。",
  "type": "object",
  "required": ["name", "type"],
  "properties": {
    "name": {
      "description": "数据源唯一标识。 [alpha]",
      "type": "string",
      "minLength": 1,
      "pattern": "^[a-z0-9][-a-z0-9_]*$"
    },
    "type": {
      "type": "string",
      "enum": ["filesystem", "s3", "oss", "confluence", "notion", "git", "web", "sharepoint", "lark-drive", "db"]
    },
    "config": {
      "description": "源类型特定配置。 [alpha]",
      "type": "object",
      "properties": {
        "baseUrl": { "type": "string", "format": "uri" },
        "spaceKey": { "type": "string" },
        "bucket": { "type": "string" },
        "prefix": { "type": "string" },
        "repoUrl": { "type": "string", "format": "uri" },
        "branch": { "type": "string" },
        "rootPath": { "type": "string" },
        "credentialRef": {
          "$ref": "https://www.anguskit.com/schema/anguscopilot/1.0.0/common.json#/$defs/SecretRef"
        }
      },
      "patternProperties": { "^x-": true },
      "unevaluatedProperties": false
    },
    "schedule": {
      "type": "object",
      "properties": {
        "mode": { "type": "string", "enum": ["full", "incremental"] },
        "cron": { "type": "string" }
      },
      "patternProperties": { "^x-": true },
      "unevaluatedProperties": false
    },
    "detection": {
      "description": "增量检测策略。 [alpha]",
      "type": "string",
      "enum": ["hash", "metadata", "webhook", "hybrid"],
      "default": "metadata"
    },
    "webhookSecretRef": {
      "description": "F3 约束：detection=webhook 时必填。 [alpha]",
      "$ref": "https://www.anguskit.com/schema/anguscopilot/1.0.0/common.json#/$defs/SecretRef"
    },
    "filters": {
      "type": "object",
      "properties": {
        "includePaths": { "type": "array", "items": { "type": "string" } },
        "excludePaths": { "type": "array", "items": { "type": "string" } },
        "maxFileSizeMb": { "type": "integer", "minimum": 1, "maximum": 1024 }
      },
      "patternProperties": { "^x-": true },
      "unevaluatedProperties": false
    }
  },
  "patternProperties": { "^x-": true },
  "$comment": "F1/F2/F3 跨字段约束。",
  "allOf": [
    {
      "$comment": "F1: type=git 必须 config.repoUrl。",
      "if": {
        "properties": { "type": { "const": "git" } },
        "required": ["type"]
      },
      "then": {
        "required": ["config"],
        "properties": {
          "config": { "required": ["repoUrl"] }
        }
      }
    },
    {
      "$comment": "F2: type=confluence 必须 config.baseUrl + spaceKey + credentialRef。",
      "if": {
        "properties": { "type": { "const": "confluence" } },
        "required": ["type"]
      },
      "then": {
        "required": ["config"],
        "properties": {
          "config": { "required": ["baseUrl", "spaceKey", "credentialRef"] }
        }
      }
    },
    {
      "$comment": "F3: detection=webhook 必须 webhookSecretRef。",
      "if": {
        "properties": { "detection": { "const": "webhook" } },
        "required": ["detection"]
      },
      "then": {
        "required": ["webhookSecretRef"]
      }
    }
  ],
  "unevaluatedProperties": false
}
