{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://hantamonitor.com/schemas/lead-links.schema.json",
  "title": "Hanta Monitor Social Lead-Link Artifact",
  "type": "object",
  "additionalProperties": true,
  "required": [
    "schema_version",
    "generated_at",
    "artifact_version",
    "generator",
    "status",
    "source_status",
    "summary",
    "sources",
    "source_evaluation_queue",
    "items"
  ],
  "properties": {
    "schema_version": { "const": 1 },
    "generated_at": { "type": "string", "format": "date-time" },
    "artifact_version": { "type": "string", "minLength": 1 },
    "generator": { "type": "string", "minLength": 1 },
    "status": { "type": "string", "minLength": 1 },
    "source_status": { "type": "object" },
    "summary": { "type": "object" },
    "sources": {
      "type": "array",
      "items": { "$ref": "#/$defs/leadSource" }
    },
    "source_evaluation_queue": {
      "type": "array",
      "items": { "$ref": "#/$defs/sourceEvaluationQueueItem" }
    },
    "items": {
      "type": "array",
      "items": { "$ref": "#/$defs/leadItem" }
    }
  },
  "$defs": {
    "languageCode": {
      "type": "string",
      "pattern": "^[a-z]{2}$"
    },
    "leadSource": {
      "type": "object",
      "additionalProperties": true,
      "required": ["id", "name", "rank", "url", "language", "source_languages", "health"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "minLength": 1 },
        "rank": { "type": "string", "minLength": 1 },
        "url": { "type": "string", "format": "uri" },
        "language": { "$ref": "#/$defs/languageCode" },
        "source_languages": {
          "type": "array",
          "minItems": 1,
          "items": { "$ref": "#/$defs/languageCode" }
        },
        "health": { "type": "object" }
      }
    },
    "leadItem": {
      "type": "object",
      "additionalProperties": true,
      "required": ["id", "title", "url", "classification", "data"],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "title": { "type": "string", "minLength": 1 },
        "url": { "type": "string", "format": "uri" },
        "classification": { "const": "lead-link" },
        "data": {
          "type": "object",
          "additionalProperties": true,
          "properties": {
            "platform": { "type": "string" },
            "platforms": {
              "type": "array",
              "items": { "type": "string" }
            },
            "outbound_url": { "type": "string", "format": "uri" },
            "outbound_domain": { "type": "string" },
            "max_like_count": { "type": "integer", "minimum": 0 },
            "max_attention_score": { "type": "integer", "minimum": 0 },
            "attention_tier": {
              "type": "string",
              "enum": ["background", "watch", "review", "urgent_review"]
            },
            "attention_threshold": { "type": "string" },
            "verification": { "type": "string" },
            "next_action": { "type": "string" },
            "evaluation_handoff": { "$ref": "#/$defs/sourceEvaluationQueueItem" },
            "platform_records": {
              "type": "array",
              "items": {
                "type": "object",
                "additionalProperties": true,
                "properties": {
                  "platform": { "type": "string" },
                  "platform_url": { "type": "string", "format": "uri" },
                  "discovered_at": { "type": "string", "format": "date-time" },
                  "community": { "type": ["string", "null"] },
                  "attention_score": { "type": "integer", "minimum": 0 },
                  "metrics": {
                    "type": "object",
                    "additionalProperties": true,
                    "properties": {
                      "retweet_count": { "type": "integer", "minimum": 0 },
                      "reply_count": { "type": "integer", "minimum": 0 },
                      "like_count": { "type": "integer", "minimum": 0 },
                      "quote_count": { "type": "integer", "minimum": 0 },
                      "bookmark_count": { "type": "integer", "minimum": 0 },
                      "impression_count": { "type": "integer", "minimum": 0 }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "sourceEvaluationQueueItem": {
      "type": "object",
      "additionalProperties": true,
      "required": [
        "id",
        "target_type",
        "target",
        "status",
        "priority",
        "reason",
        "next_action",
        "first_seen_at",
        "last_seen_at",
        "mention_count",
        "platforms",
        "lead_item_ids",
        "outbound_urls"
      ],
      "properties": {
        "id": { "type": "string", "minLength": 1 },
        "target_type": { "const": "domain" },
        "target": { "type": "string", "minLength": 1 },
        "status": { "const": "pending-review" },
        "priority": {
          "type": "string",
          "enum": ["low", "medium", "high"]
        },
        "reason": { "type": "string", "minLength": 1 },
        "next_action": { "const": "evaluate-source-domain" },
        "first_seen_at": { "type": "string", "format": "date-time" },
        "last_seen_at": { "type": "string", "format": "date-time" },
        "mention_count": { "type": "integer", "minimum": 0 },
        "platforms": {
          "type": "array",
          "items": { "type": "string" }
        },
        "lead_item_ids": {
          "type": "array",
          "items": { "type": "string" }
        },
        "outbound_urls": {
          "type": "array",
          "items": { "type": "string", "format": "uri" }
        }
      }
    }
  }
}
