{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://www.growthcab.com/assets/outbound-evidence-record.schema.json",
  "title": "Growth Cab outbound evidence record",
  "description": "A privacy-safe record for preserving metric lineage from campaign activity to revenue.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "campaign_id",
    "event_id",
    "event_type",
    "occurred_at",
    "account_id",
    "source_channel",
    "attribution_rule",
    "evidence_uri",
    "snapshot_at",
    "metric_version"
  ],
  "properties": {
    "campaign_id": { "type": "string", "minLength": 1 },
    "event_id": { "type": "string", "minLength": 1 },
    "event_type": {
      "type": "string",
      "enum": ["exposure", "response", "booked_meeting", "held_meeting", "no_show", "qualified_opportunity", "closed_won", "closed_lost", "payment"]
    },
    "occurred_at": { "type": "string", "format": "date-time" },
    "account_id": { "type": "string", "minLength": 1 },
    "person_id_hash": { "type": "string" },
    "opportunity_id": { "type": "string" },
    "stage": { "type": "string" },
    "amount": { "type": "number", "minimum": 0 },
    "currency": { "type": "string", "pattern": "^[A-Z]{3}$" },
    "amount_type": {
      "type": "string",
      "enum": ["forecast_pipeline", "weighted_pipeline", "contracted_revenue", "paid_revenue"]
    },
    "source_channel": { "type": "string", "minLength": 1 },
    "attribution_rule": { "type": "string", "minLength": 1 },
    "evidence_uri": { "type": "string", "minLength": 1 },
    "snapshot_at": { "type": "string", "format": "date-time" },
    "metric_version": { "type": "string", "pattern": "^[0-9]+\\.[0-9]+(?:\\.[0-9]+)?$" }
  },
  "allOf": [
    {
      "if": { "required": ["amount"] },
      "then": { "required": ["currency", "amount_type"] }
    },
    {
      "if": { "properties": { "event_type": { "const": "qualified_opportunity" } } },
      "then": { "required": ["opportunity_id"] }
    }
  ]
}
