{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "Beacon interests v1",
  "$defs": {
    "SourceKind": {
      "type": "string",
      "enum": [
        "publisher",
        "merchant",
        "account",
        "companion",
        "partner"
      ]
    },
    "EventKind": {
      "type": "string",
      "enum": [
        "page_view",
        "history_visit",
        "link_click",
        "engaged_read",
        "search",
        "product_view",
        "save",
        "cart",
        "purchase",
        "refund",
        "dismiss",
        "declared_interest"
      ]
    },
    "Content": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "url": {
          "type": "string"
        },
        "title": {
          "type": "string"
        },
        "description": {
          "type": "string"
        },
        "headings": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "text": {
          "type": "string"
        },
        "query": {
          "type": "string"
        }
      },
      "required": []
    },
    "Engagement": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "activeSeconds": {
          "type": "number",
          "minimum": 0,
          "maximum": 86400
        },
        "scrollFraction": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        }
      },
      "required": []
    },
    "Evidence": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": 1
        },
        "id": {
          "type": "string"
        },
        "subjectId": {
          "type": "string"
        },
        "sourceKey": {
          "type": "string"
        },
        "sourceKind": {
          "$ref": "#/$defs/SourceKind"
        },
        "sessionId": {
          "type": "string"
        },
        "occurredAt": {
          "type": "string",
          "format": "date-time"
        },
        "kind": {
          "$ref": "#/$defs/EventKind"
        },
        "content": {
          "$ref": "#/$defs/Content"
        },
        "engagement": {
          "$ref": "#/$defs/Engagement"
        },
        "referenceId": {
          "type": "string"
        },
        "timePrecision": {
          "type": "string",
          "enum": [
            "instant",
            "day"
          ]
        }
      },
      "required": [
        "schemaVersion",
        "id",
        "subjectId",
        "sourceKey",
        "sourceKind",
        "sessionId",
        "occurredAt",
        "kind",
        "content"
      ]
    },
    "TopicMatch": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "topicId": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "relevance": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "matchedTerms": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "topicId",
        "label",
        "relevance",
        "matchedTerms"
      ]
    },
    "Affinity": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "topicId": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "score": {
          "type": "number"
        },
        "intentScore": {
          "type": "number"
        },
        "strength": {
          "type": "string",
          "enum": [
            "tentative",
            "supported",
            "explicit"
          ]
        },
        "lastObservedAt": {
          "type": "string"
        },
        "evidenceIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "sourceKinds": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/SourceKind"
          }
        },
        "distinctSessions": {
          "type": "integer",
          "minimum": 0
        }
      },
      "required": [
        "topicId",
        "label",
        "score",
        "intentScore",
        "strength",
        "lastObservedAt",
        "evidenceIds",
        "sourceKinds",
        "distinctSessions"
      ]
    },
    "InterestProfile": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": 1
        },
        "subjectId": {
          "type": "string"
        },
        "asOf": {
          "type": "string"
        },
        "policyVersion": {
          "type": "string"
        },
        "interests": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/Affinity"
          }
        },
        "contextualTopics": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/TopicMatch"
          }
        }
      },
      "required": [
        "schemaVersion",
        "subjectId",
        "asOf",
        "policyVersion",
        "interests",
        "contextualTopics"
      ]
    },
    "Offer": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string"
        },
        "variantId": {
          "type": "string"
        },
        "priceMinor": {
          "type": "integer"
        },
        "currency": {
          "type": "string"
        },
        "available": {
          "type": "boolean"
        }
      },
      "required": [
        "id",
        "variantId",
        "priceMinor",
        "currency",
        "available"
      ]
    },
    "Creative": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string"
        },
        "offerId": {
          "type": "string"
        },
        "variantId": {
          "type": "string"
        },
        "topics": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "ready": {
          "type": "boolean"
        },
        "fallback": {
          "type": "boolean"
        }
      },
      "required": [
        "id",
        "offerId",
        "variantId",
        "topics",
        "ready",
        "fallback"
      ]
    },
    "Presentation": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "creativeId": {
          "type": "string"
        },
        "offer": {
          "$ref": "#/$defs/Offer"
        },
        "reason": {
          "type": "string"
        },
        "topicIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "evidenceIds": {
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "creativeId",
        "offer",
        "reason",
        "topicIds",
        "evidenceIds"
      ]
    },
    "AgentInterestKind": {
      "type": "string",
      "enum": [
        "affinity",
        "in_market",
        "dislike"
      ]
    },
    "AgentPurpose": {
      "type": "string",
      "enum": [
        "ads",
        "personalization"
      ]
    },
    "AgentInterestEvent": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "schemaVersion": {
          "const": 1
        },
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "grantId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "appSubjectId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "conversationId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "topicId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "kind": {
          "$ref": "#/$defs/AgentInterestKind"
        },
        "origin": {
          "type": "string",
          "enum": [
            "user_statement",
            "user_action",
            "ad_response",
            "agent_text"
          ],
          "minLength": 1,
          "maxLength": 200
        },
        "about": {
          "type": "string",
          "enum": [
            "user",
            "other",
            "hypothetical"
          ],
          "minLength": 1,
          "maxLength": 200
        },
        "confidence": {
          "type": "number",
          "minimum": 0,
          "maximum": 1
        },
        "observedAtMs": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "expiresAtMs": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "evidenceRef": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        }
      },
      "required": [
        "schemaVersion",
        "id",
        "grantId",
        "appSubjectId",
        "conversationId",
        "topicId",
        "kind",
        "origin",
        "about",
        "confidence",
        "observedAtMs",
        "expiresAtMs",
        "evidenceRef"
      ]
    },
    "AgentGrant": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "appId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "appSubjectId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "profileId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "grantId": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "learn": {
          "type": "boolean"
        },
        "ads": {
          "type": "boolean"
        },
        "personalization": {
          "type": "boolean"
        },
        "network": {
          "type": "boolean"
        },
        "expiresAtMs": {
          "type": "integer",
          "minimum": 0,
          "maximum": 9007199254740991
        },
        "revoked": {
          "type": "boolean"
        }
      },
      "required": [
        "appId",
        "appSubjectId",
        "profileId",
        "grantId",
        "learn",
        "ads",
        "personalization",
        "network",
        "expiresAtMs",
        "revoked"
      ]
    },
    "AgentApp": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "hasAgent": {
          "type": "boolean"
        }
      },
      "required": [
        "id",
        "hasAgent"
      ]
    },
    "AgentTopicScore": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "topicId": {
          "type": "string"
        },
        "label": {
          "type": "string"
        },
        "kind": {
          "$ref": "#/$defs/AgentInterestKind"
        },
        "score": {
          "type": "number"
        },
        "evidenceCount": {
          "type": "integer"
        },
        "supportingApps": {
          "type": "integer"
        },
        "lastObservedAtMs": {
          "type": "integer"
        },
        "expiresAtMs": {
          "type": "integer"
        }
      },
      "required": [
        "topicId",
        "label",
        "kind",
        "score",
        "evidenceCount",
        "supportingApps",
        "lastObservedAtMs",
        "expiresAtMs"
      ]
    },
    "AgentProfile": {
      "type": "object",
      "additionalProperties": false,
      "properties": {
        "taxonomyVersion": {
          "type": "string"
        },
        "asOfMs": {
          "type": "integer"
        },
        "purpose": {
          "$ref": "#/$defs/AgentPurpose"
        },
        "topics": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/AgentTopicScore"
          }
        }
      },
      "required": [
        "taxonomyVersion",
        "asOfMs",
        "purpose",
        "topics"
      ]
    }
  },
  "$ref": "#/$defs/Evidence"
}
