{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/past-dev/json-schema/past-dev-audience-schema.json",
  "title": "Audience",
  "x-generated": "2026-11-10",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/past-dev-audiences-api-openapi.yml#/components/schemas/Audience",
  "type": "object",
  "required": [
    "slug",
    "name",
    "kind",
    "memberCount",
    "memoryCount",
    "reachesNobody",
    "recomputedAt",
    "createdAt",
    "identities",
    "rule"
  ],
  "additionalProperties": false,
  "properties": {
    "slug": {
      "type": "string"
    },
    "name": {
      "type": "string"
    },
    "kind": {
      "type": "string",
      "enum": [
        "fixed",
        "rule",
        "default"
      ]
    },
    "memberCount": {
      "type": "integer",
      "description": "The identities the audience reaches now."
    },
    "memoryCount": {
      "type": "integer",
      "description": "The memories scoped to this audience."
    },
    "reachesNobody": {
      "type": "boolean",
      "description": "True for a rule audience that matches no identity."
    },
    "recomputedAt": {
      "type": [
        "string",
        "null"
      ],
      "format": "date-time"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time"
    },
    "identities": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": "string"
      },
      "description": "The ids of a fixed audience, sorted. Null for the other kinds."
    },
    "rule": {
      "oneOf": [
        {
          "$ref": "#/$defs/AudienceRule"
        },
        {
          "type": "null"
        }
      ],
      "description": "The rule of a rule audience. Null for the other kinds."
    }
  },
  "$defs": {
    "AudienceCondition": {
      "type": "object",
      "required": [
        "trait",
        "operator"
      ],
      "additionalProperties": false,
      "properties": {
        "trait": {
          "type": "string",
          "minLength": 1,
          "maxLength": 200
        },
        "operator": {
          "type": "string",
          "enum": [
            "is",
            "is_not",
            "is_one_of",
            "is_not_one_of",
            "exists",
            "does_not_exist"
          ]
        },
        "values": {
          "type": "array",
          "maxItems": 50,
          "items": {
            "type": "string"
          },
          "description": "One value for is and is_not, 1 to 50 for is_one_of and is_not_one_of, none for exists and does_not_exist."
        }
      }
    },
    "AudienceRule": {
      "type": "object",
      "required": [
        "match",
        "conditions"
      ],
      "additionalProperties": false,
      "properties": {
        "match": {
          "type": "string",
          "enum": [
            "all",
            "any"
          ]
        },
        "conditions": {
          "type": "array",
          "minItems": 1,
          "maxItems": 20,
          "items": {
            "$ref": "#/$defs/AudienceCondition"
          }
        }
      }
    }
  }
}