{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "/schemas/3.0.9/media-buy/sync-audiences-response.json",
  "title": "Sync Audiences Response",
  "description": "Response from audience sync operation. Returns either per-audience results OR operation-level errors.",
  "type": "object",
  "oneOf": [
    {
      "title": "SyncAudiencesSuccess",
      "description": "Success response - sync operation processed audiences",
      "type": "object",
      "properties": {
        "audiences": {
          "type": "array",
          "description": "Results for each audience on the account",
          "items": {
            "type": "object",
            "properties": {
              "audience_id": {
                "type": "string",
                "description": "Audience ID from the request (buyer's identifier)",
                "x-entity": "audience"
              },
              "name": {
                "type": "string",
                "description": "Name of the audience"
              },
              "seller_id": {
                "type": "string",
                "description": "Seller-assigned identifier for this audience in their ad platform"
              },
              "action": {
                "type": "string",
                "enum": ["created", "updated", "unchanged", "deleted", "failed"],
                "description": "Action taken for this audience. 'status' is present when action is created, updated, or unchanged. 'status' is absent when action is deleted or failed."
              },
              "status": {
                "$ref": "/schemas/3.0.9/enums/audience-status.json",
                "description": "Matching status. Present when action is created, updated, or unchanged; absent when action is deleted or failed."
              },
              "uploaded_count": {
                "type": "integer",
                "description": "Number of members submitted in this sync operation (delta, not cumulative). In discovery-only calls (no audiences array), this is 0.",
                "minimum": 0
              },
              "total_uploaded_count": {
                "type": "integer",
                "description": "Cumulative number of members uploaded across all syncs for this audience. Compare with matched_count to calculate match rate (matched_count / total_uploaded_count). Populated when the seller tracks cumulative upload counts.",
                "minimum": 0
              },
              "matched_count": {
                "type": "integer",
                "description": "Total members matched to platform users across all syncs (cumulative, not just this call). Populated when status is 'ready'.",
                "minimum": 0
              },
              "effective_match_rate": {
                "type": "number",
                "description": "Deduplicated match rate across all identifier types (matched_count / total_uploaded_count after deduplication). A single number for reach estimation. Populated when status is 'ready'.",
                "minimum": 0,
                "maximum": 1
              },
              "match_breakdown": {
                "type": "array",
                "description": "Per-identifier-type match results. Shows which ID types are resolving and at what rate. Helps buyers decide which identifiers to prioritize. Populated when the seller can report per-type matching. Omitted when the seller only supports aggregate match counts.",
                "items": {
                  "type": "object",
                  "properties": {
                    "id_type": {
                      "$ref": "/schemas/3.0.9/enums/match-id-type.json",
                      "description": "Identifier type. Combines hashed PII types (hashed_email, hashed_phone) with universal ID types (rampid, uid2, maid, etc.)."
                    },
                    "submitted": {
                      "type": "integer",
                      "description": "Cumulative number of members submitted with this identifier type across all syncs (matches total_uploaded_count semantics, not uploaded_count). Compare with matched to calculate per-type match rate.",
                      "minimum": 0
                    },
                    "matched": {
                      "type": "integer",
                      "description": "Cumulative number of members matched via this identifier type across all syncs.",
                      "minimum": 0
                    },
                    "match_rate": {
                      "type": "number",
                      "description": "Match rate for this identifier type (matched / submitted). Server-authoritative — consumers should prefer this value over computing their own.",
                      "minimum": 0,
                      "maximum": 1
                    }
                  },
                  "required": ["id_type", "submitted", "matched", "match_rate"],
                  "additionalProperties": true
                },
                "minItems": 1
              },
              "last_synced_at": {
                "type": "string",
                "format": "date-time",
                "description": "ISO 8601 timestamp of when the most recent sync operation was accepted by the platform. Useful for agents reasoning about audience freshness. Omitted if the seller does not track this."
              },
              "minimum_size": {
                "type": "integer",
                "description": "Minimum matched audience size required for targeting on this platform. Populated when status is 'too_small'. Helps agents know how many more members are needed.",
                "minimum": 1
              },
              "errors": {
                "type": "array",
                "description": "Errors for this audience (only present when action='failed')",
                "items": {
                  "$ref": "/schemas/3.0.9/core/error.json"
                }
              }
            },
            "required": ["audience_id", "action"],
            "additionalProperties": true
          }
        },
        "sandbox": {
          "type": "boolean",
          "description": "When true, this response contains simulated data from sandbox mode."
        },
        "context": {
          "$ref": "/schemas/3.0.9/core/context.json"
        },
        "ext": {
          "$ref": "/schemas/3.0.9/core/ext.json"
        }
      },
      "required": ["audiences"],
      "additionalProperties": true,
      "not": {
        "required": ["errors"]
      }
    },
    {
      "title": "SyncAudiencesError",
      "description": "Error response - operation failed completely",
      "type": "object",
      "properties": {
        "errors": {
          "type": "array",
          "description": "Operation-level errors that prevented processing",
          "items": {
            "$ref": "/schemas/3.0.9/core/error.json"
          },
          "minItems": 1
        },
        "context": {
          "$ref": "/schemas/3.0.9/core/context.json"
        },
        "ext": {
          "$ref": "/schemas/3.0.9/core/ext.json"
        }
      },
      "required": ["errors"],
      "additionalProperties": true,
      "not": {
        "anyOf": [
          { "required": ["audiences"] },
          { "required": ["sandbox"] }
        ]
      }
    }
  ]
}
