{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://triplewhale.com/schemas/ad",
  "title": "Triple Whale Ad Record",
  "description": "Schema for ingesting advertising data into Triple Whale via the Data-In API.",
  "type": "object",
  "required": ["shop", "channel", "event_date", "currency"],
  "properties": {
    "shop": {
      "type": "string",
      "description": "The exact Shop URL matching the store in Triple Whale settings.",
      "example": "madisonbraids.myshopify.com"
    },
    "channel": {
      "type": "string",
      "description": "The advertising platform. Use a Standardized Ad Channel ID or custom value.",
      "example": "facebook-ads"
    },
    "channel_account_id": {
      "type": "string",
      "description": "The platform-specific account ID.",
      "default": "CUSTOM_CHANNEL",
      "example": "example_fb_account"
    },
    "event_date": {
      "type": "string",
      "format": "date",
      "description": "The date of the event in YYYY-MM-DD format.",
      "example": "2024-11-28"
    },
    "currency": {
      "type": "string",
      "description": "The currency used for reporting.",
      "example": "USD"
    },
    "campaign": {
      "type": "object",
      "description": "Advertising campaign details. At least one of campaign, adset, or ad is required.",
      "required": ["id", "name", "status"],
      "properties": {
        "id": {"type": "string", "example": "campaign_example_id"},
        "name": {"type": "string", "example": "Example Campaign"},
        "status": {"type": "string", "enum": ["PAUSED", "ACTIVE"]}
      }
    },
    "adset": {
      "type": "object",
      "description": "Ad set details. At least one of campaign, adset, or ad is required.",
      "required": ["id", "name", "status"],
      "properties": {
        "id": {"type": "string"},
        "name": {"type": "string"},
        "status": {"type": "string", "enum": ["PAUSED", "ACTIVE"]}
      }
    },
    "ad": {
      "type": "object",
      "description": "Individual ad details. At least one of campaign, adset, or ad is required.",
      "required": ["id", "name", "status"],
      "properties": {
        "id": {"type": "string"},
        "name": {"type": "string"},
        "status": {"type": "string", "enum": ["PAUSED", "ACTIVE"]},
        "thumbnail": {"type": "string", "description": "URL of the ad thumbnail image."}
      }
    },
    "metrics": {
      "type": "object",
      "description": "Performance metrics for the ad.",
      "properties": {
        "clicks": {"type": "number", "default": 0, "example": 1500},
        "conversions": {"type": "number", "default": 0, "example": 75},
        "conversion_value": {"type": "number", "default": 0, "example": 3750.5},
        "impressions": {"type": "number", "default": 0, "example": 25000},
        "spend": {"type": "number", "default": 0, "example": 500},
        "visits": {"type": "number", "default": 0, "example": 2000}
      }
    },
    "updated_at": {
      "type": "string",
      "format": "date-time",
      "description": "ISO 8601 timestamp when the ad record was last updated.",
      "example": "2024-11-28T15:30:00Z"
    }
  }
}
