asyncapi: 2.6.0
info:
  title: EventZR CRM Service Async API
  version: 1.0.0
  description: |
    Asynchronous event specification for the CRM Service.
    All messages use CloudEvents 1.0 envelope format over Apache Kafka (Amazon MSK Serverless).
    Partition key is tenantId for all topics.
  contact:
    name: Gaurav Garg
    email: gaurav@epiqueevents.com
  license:
    name: Proprietary

servers:
  staging:
    url: boot-gpm4u49z.c2.kafka-serverless.us-east-1.amazonaws.com:9098
    protocol: kafka
    description: Amazon MSK Serverless (Staging)
    security:
      - saslIam: []

defaultContentType: application/cloudevents+json

channels:
  # =====================================================================
  # PRODUCED TOPICS (12 producers, ~20 unique topics)
  # =====================================================================

  eventzr.crm.contact.v1:
    description: Contact lifecycle events
    publish:
      operationId: publishContactEvent
      summary: Contact created, updated, deleted, merged, enriched, or tags updated
      message:
        oneOf:
          - $ref: '#/components/messages/ContactCreated'
          - $ref: '#/components/messages/ContactUpdated'
          - $ref: '#/components/messages/ContactDeleted'
          - $ref: '#/components/messages/ContactMerged'
          - $ref: '#/components/messages/ContactEnriched'
          - $ref: '#/components/messages/ContactTagsUpdated'

  eventzr.crm.account.created.v1:
    description: Account created event
    publish:
      operationId: publishAccountCreated
      message:
        $ref: '#/components/messages/AccountCreated'

  eventzr.crm.account.updated.v1:
    description: Account updated event
    publish:
      operationId: publishAccountUpdated
      message:
        $ref: '#/components/messages/AccountUpdated'

  eventzr.crm.account.deleted.v1:
    description: Account deleted event
    publish:
      operationId: publishAccountDeleted
      message:
        $ref: '#/components/messages/AccountDeleted'

  eventzr.crm.deal.v1:
    description: Deal lifecycle events
    publish:
      operationId: publishDealEvent
      summary: Deal created, updated, deleted, stage changed, closed won, or closed lost
      message:
        oneOf:
          - $ref: '#/components/messages/DealCreated'
          - $ref: '#/components/messages/DealUpdated'
          - $ref: '#/components/messages/DealDeleted'
          - $ref: '#/components/messages/DealStageChanged'
          - $ref: '#/components/messages/DealClosedWon'
          - $ref: '#/components/messages/DealClosedLost'

  eventzr.crm.activity.v1:
    description: Activity lifecycle events
    publish:
      operationId: publishActivityEvent
      summary: Activity created, updated, or deleted
      message:
        oneOf:
          - $ref: '#/components/messages/ActivityCreated'
          - $ref: '#/components/messages/ActivityUpdated'
          - $ref: '#/components/messages/ActivityDeleted'

  eventzr.crm.list.v1:
    description: Contact list lifecycle events
    publish:
      operationId: publishListEvent
      summary: List created, updated, deleted, members added/removed, or refreshed
      message:
        oneOf:
          - $ref: '#/components/messages/ListCreated'
          - $ref: '#/components/messages/ListUpdated'
          - $ref: '#/components/messages/ListDeleted'
          - $ref: '#/components/messages/ListMembersAdded'
          - $ref: '#/components/messages/ListMembersRemoved'
          - $ref: '#/components/messages/ListRefreshed'

  eventzr.crm.pipeline.v1:
    description: Pipeline and stage lifecycle events
    publish:
      operationId: publishPipelineEvent
      summary: Pipeline created, updated, deleted, stage added, or stages reordered
      message:
        oneOf:
          - $ref: '#/components/messages/PipelineCreated'
          - $ref: '#/components/messages/PipelineUpdated'
          - $ref: '#/components/messages/PipelineDeleted'
          - $ref: '#/components/messages/PipelineStageAdded'
          - $ref: '#/components/messages/PipelineStagesReordered'

  eventzr.crm.campaign.started.v1:
    description: Campaign execution started
    publish:
      operationId: publishCampaignStarted
      message:
        $ref: '#/components/messages/CampaignStarted'

  eventzr.crm.campaign.progress.v1:
    description: Campaign execution progress update
    publish:
      operationId: publishCampaignProgress
      message:
        $ref: '#/components/messages/CampaignProgress'

  eventzr.crm.campaign.completed.v1:
    description: Campaign execution completed successfully
    publish:
      operationId: publishCampaignCompleted
      message:
        $ref: '#/components/messages/CampaignCompleted'

  eventzr.crm.campaign.failed.v1:
    description: Campaign execution failed
    publish:
      operationId: publishCampaignFailed
      message:
        $ref: '#/components/messages/CampaignFailed'

  eventzr.crm.connector.v1:
    description: External CRM connector events
    publish:
      operationId: publishConnectorEvent
      summary: Connector created, synced, or sync failed
      message:
        oneOf:
          - $ref: '#/components/messages/ConnectorCreated'
          - $ref: '#/components/messages/ConnectorSynced'
          - $ref: '#/components/messages/ConnectorFailed'

  eventzr.crm.import.started.v1:
    description: Data import started
    publish:
      operationId: publishImportStarted
      message:
        $ref: '#/components/messages/ImportStarted'

  eventzr.crm.import.progress.v1:
    description: Data import progress update
    publish:
      operationId: publishImportProgress
      message:
        $ref: '#/components/messages/ImportProgress'

  eventzr.crm.import.completed.v1:
    description: Data import completed successfully
    publish:
      operationId: publishImportCompleted
      message:
        $ref: '#/components/messages/ImportCompleted'

  eventzr.crm.import.failed.v1:
    description: Data import failed
    publish:
      operationId: publishImportFailed
      message:
        $ref: '#/components/messages/ImportFailed'

  eventzr.crm.staff.v1:
    description: Staff incentive events
    publish:
      operationId: publishStaffEvent
      message:
        $ref: '#/components/messages/StaffIncentiveRecorded'

  eventzr.ai.requests.v1:
    description: AI enrichment, scoring, and classification requests sent to aibrain-svc
    publish:
      operationId: publishAIRequest
      message:
        $ref: '#/components/messages/AIRequest'

  eventzr.kg.v1:
    description: Knowledge graph projection events sent to Neptune for node/edge synchronization
    publish:
      operationId: publishKGEvent
      message:
        $ref: '#/components/messages/KGEvent'

  # =====================================================================
  # CONSUMED TOPICS (15 consumers, ~30 unique topics)
  # =====================================================================

  # --- AI Brain Results (8 topics) ---

  eventzr.aibrain.scoring.completed.v1:
    description: AI lead/contact scoring result (from aibrain-svc)
    subscribe:
      operationId: onAIScoringCompleted
      message:
        $ref: '#/components/messages/AIBrainResult'

  eventzr.aibrain.enrichment.completed.v1:
    description: AI enrichment result (from aibrain-svc)
    subscribe:
      operationId: onAIEnrichmentCompleted
      message:
        $ref: '#/components/messages/AIBrainResult'

  eventzr.aibrain.classification.completed.v1:
    description: AI classification result (from aibrain-svc)
    subscribe:
      operationId: onAIClassificationCompleted
      message:
        $ref: '#/components/messages/AIBrainResult'

  eventzr.aibrain.recommendation.completed.v1:
    description: AI recommendation result (from aibrain-svc)
    subscribe:
      operationId: onAIRecommendationCompleted
      message:
        $ref: '#/components/messages/AIBrainResult'

  eventzr.aibrain.sentiment.completed.v1:
    description: AI sentiment analysis result (from aibrain-svc)
    subscribe:
      operationId: onAISentimentCompleted
      message:
        $ref: '#/components/messages/AIBrainResult'

  eventzr.aibrain.lead_qualification.completed.v1:
    description: AI lead qualification result (from aibrain-svc)
    subscribe:
      operationId: onAILeadQualificationCompleted
      message:
        $ref: '#/components/messages/AIBrainResult'

  eventzr.aibrain.churn_prediction.completed.v1:
    description: AI churn prediction result (from aibrain-svc)
    subscribe:
      operationId: onAIChurnPredictionCompleted
      message:
        $ref: '#/components/messages/AIBrainResult'

  eventzr.aibrain.next_best_action.completed.v1:
    description: AI next-best-action recommendation (from aibrain-svc)
    subscribe:
      operationId: onAINextBestActionCompleted
      message:
        $ref: '#/components/messages/AIBrainResult'

  # --- Integration Hub (1 topic) ---

  eventzr.integrationhub.webhook.received.v1:
    description: Inbound webhook received (from integration-hub-svc)
    subscribe:
      operationId: onWebhookReceived
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  # --- Event Service (2 topics) ---

  eventzr.event.registration.created.v1:
    description: Event registration created (from event-svc) - auto-creates/updates CRM contact
    subscribe:
      operationId: onEventRegistrationCreated
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.event.attendance.recorded.v1:
    description: Event attendance recorded (from event-svc) - updates contact engagement score
    subscribe:
      operationId: onEventAttendanceRecorded
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  # --- Subscriptions Service (7 topics) ---

  eventzr.subscriptions.subscription.created.v1:
    description: Subscription created (from subscriptions-svc)
    subscribe:
      operationId: onSubscriptionCreated
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.subscriptions.subscription.renewed.v1:
    description: Subscription renewed
    subscribe:
      operationId: onSubscriptionRenewed
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.subscriptions.subscription.cancelled.v1:
    description: Subscription cancelled
    subscribe:
      operationId: onSubscriptionCancelled
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.subscriptions.subscription.upgraded.v1:
    description: Subscription upgraded
    subscribe:
      operationId: onSubscriptionUpgraded
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.subscriptions.subscription.downgraded.v1:
    description: Subscription downgraded
    subscribe:
      operationId: onSubscriptionDowngraded
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.subscriptions.subscription.trial.started.v1:
    description: Subscription trial started
    subscribe:
      operationId: onSubscriptionTrialStarted
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.subscriptions.subscription.trial.expired.v1:
    description: Subscription trial expired
    subscribe:
      operationId: onSubscriptionTrialExpired
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  # --- Notify Service (6 topics) ---

  eventzr.notify.email.delivered.v1:
    description: Email delivered (from notify-svc) - updates campaign metrics
    subscribe:
      operationId: onEmailDelivered
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.notify.email.opened.v1:
    description: Email opened (from notify-svc)
    subscribe:
      operationId: onEmailOpened
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.notify.email.clicked.v1:
    description: Email link clicked (from notify-svc)
    subscribe:
      operationId: onEmailClicked
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.notify.email.bounced.v1:
    description: Email bounced (from notify-svc)
    subscribe:
      operationId: onEmailBounced
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.notify.email.unsubscribed.v1:
    description: Email unsubscribed (from notify-svc)
    subscribe:
      operationId: onEmailUnsubscribed
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.notify.email.complaint.v1:
    description: Email complaint received (from notify-svc)
    subscribe:
      operationId: onEmailComplaint
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.notify.whatsapp.delivered.v1:
    description: WhatsApp message delivered (from notify-svc)
    subscribe:
      operationId: onWhatsAppDelivered
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.notify.whatsapp.read.v1:
    description: WhatsApp message read (from notify-svc)
    subscribe:
      operationId: onWhatsAppRead
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.notify.whatsapp.replied.v1:
    description: WhatsApp reply received (from notify-svc)
    subscribe:
      operationId: onWhatsAppReplied
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  # --- Sphere Service (1 topic) ---

  eventzr.sphere.user.updated.v1:
    description: User profile updated (from sphere-svc) - syncs CRM contact fields
    subscribe:
      operationId: onSphereUserUpdated
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  # --- Booking Service (4 topics) ---

  eventzr.booking.booking.created.v1:
    description: Booking created (from booking-svc) - creates activity on contact
    subscribe:
      operationId: onBookingCreated
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.booking.booking.confirmed.v1:
    description: Booking confirmed (from booking-svc)
    subscribe:
      operationId: onBookingConfirmed
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.booking.booking.cancelled.v1:
    description: Booking cancelled (from booking-svc)
    subscribe:
      operationId: onBookingCancelled
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.booking.booking.checked_in.v1:
    description: Booking checked in (from booking-svc)
    subscribe:
      operationId: onBookingCheckedIn
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  # --- Taxonomy Service (1 topic) ---

  eventzr.taxonomy.tag.updated.v1:
    description: Taxonomy tag updated (from taxonomy-svc) - syncs CRM contact tags
    subscribe:
      operationId: onTaxonomyTagUpdated
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  # --- Wallet Service (6 topics) ---

  eventzr.wallet.payment.completed.v1:
    description: Payment completed (from wallet-svc) - updates deal/contact revenue
    subscribe:
      operationId: onPaymentCompleted
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.wallet.payment.succeeded.v1:
    description: Payment succeeded (from wallet-svc)
    subscribe:
      operationId: onPaymentSucceeded
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.wallet.payment.failed.v1:
    description: Payment failed (from wallet-svc)
    subscribe:
      operationId: onPaymentFailed
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.wallet.payment.refunded.v1:
    description: Payment refunded (from wallet-svc)
    subscribe:
      operationId: onPaymentRefunded
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.wallet.payment.disputed.v1:
    description: Payment disputed (from wallet-svc)
    subscribe:
      operationId: onPaymentDisputed
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.wallet.transaction.completed.v1:
    description: Transaction completed (from wallet-svc)
    subscribe:
      operationId: onTransactionCompleted
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.wallet.points.earned.v1:
    description: Loyalty points earned (from wallet-svc) - updates contact engagement
    subscribe:
      operationId: onPointsEarned
      message:
        $ref: '#/components/messages/GenericCloudEvent'

  eventzr.wallet.points.redeemed.v1:
    description: Loyalty points redeemed (from wallet-svc)
    subscribe:
      operationId: onPointsRedeemed
      message:
        $ref: '#/components/messages/GenericCloudEvent'

components:
  securitySchemes:
    saslIam:
      type: scramSha512
      description: AWS MSK IAM authentication via SASL

  messages:
    # ─── Contact Messages ─────────────────────────────────────────────

    ContactCreated:
      name: ContactCreated
      title: Contact Created
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.contact.created.v1

    ContactUpdated:
      name: ContactUpdated
      title: Contact Updated
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.contact.updated.v1

    ContactDeleted:
      name: ContactDeleted
      title: Contact Deleted
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.contact.deleted.v1

    ContactMerged:
      name: ContactMerged
      title: Contacts Merged
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.contact.merged.v1

    ContactEnriched:
      name: ContactEnriched
      title: Contact Enriched (AI)
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.contact.enriched.v1

    ContactTagsUpdated:
      name: ContactTagsUpdated
      title: Contact Tags Updated
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.contact.tags.updated.v1

    # ─── Account Messages ─────────────────────────────────────────────

    AccountCreated:
      name: AccountCreated
      title: Account Created
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.account.created.v1

    AccountUpdated:
      name: AccountUpdated
      title: Account Updated
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.account.updated.v1

    AccountDeleted:
      name: AccountDeleted
      title: Account Deleted
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.account.deleted.v1

    # ─── Deal Messages ────────────────────────────────────────────────

    DealCreated:
      name: DealCreated
      title: Deal Created
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.deal.created.v1

    DealUpdated:
      name: DealUpdated
      title: Deal Updated
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.deal.updated.v1

    DealDeleted:
      name: DealDeleted
      title: Deal Deleted
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.deal.deleted.v1

    DealStageChanged:
      name: DealStageChanged
      title: Deal Stage Changed
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.deal.stage.changed.v1

    DealClosedWon:
      name: DealClosedWon
      title: Deal Closed Won
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.deal.closed.won.v1

    DealClosedLost:
      name: DealClosedLost
      title: Deal Closed Lost
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.deal.closed.lost.v1

    # ─── Activity Messages ────────────────────────────────────────────

    ActivityCreated:
      name: ActivityCreated
      title: Activity Created
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.activity.created.v1

    ActivityUpdated:
      name: ActivityUpdated
      title: Activity Updated
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.activity.updated.v1

    ActivityDeleted:
      name: ActivityDeleted
      title: Activity Deleted
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.activity.deleted.v1

    # ─── List Messages ────────────────────────────────────────────────

    ListCreated:
      name: ListCreated
      title: Contact List Created
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.list.created.v1

    ListUpdated:
      name: ListUpdated
      title: Contact List Updated
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.list.updated.v1

    ListDeleted:
      name: ListDeleted
      title: Contact List Deleted
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.list.deleted.v1

    ListMembersAdded:
      name: ListMembersAdded
      title: List Members Added
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.list.members.added.v1

    ListMembersRemoved:
      name: ListMembersRemoved
      title: List Members Removed
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.list.members.removed.v1

    ListRefreshed:
      name: ListRefreshed
      title: Dynamic List Refreshed
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.list.refreshed.v1

    # ─── Pipeline Messages ────────────────────────────────────────────

    PipelineCreated:
      name: PipelineCreated
      title: Pipeline Created
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.pipeline.created.v1

    PipelineUpdated:
      name: PipelineUpdated
      title: Pipeline Updated
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.pipeline.updated.v1

    PipelineDeleted:
      name: PipelineDeleted
      title: Pipeline Deleted
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.pipeline.deleted.v1

    PipelineStageAdded:
      name: PipelineStageAdded
      title: Pipeline Stage Added
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.pipeline.stage.added.v1

    PipelineStagesReordered:
      name: PipelineStagesReordered
      title: Pipeline Stages Reordered
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.pipeline.stages.reordered.v1

    # ─── Campaign Messages ────────────────────────────────────────────

    CampaignStarted:
      name: CampaignStarted
      title: Campaign Started
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.campaign.started.v1

    CampaignProgress:
      name: CampaignProgress
      title: Campaign Progress
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.campaign.progress.v1

    CampaignCompleted:
      name: CampaignCompleted
      title: Campaign Completed
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.campaign.completed.v1

    CampaignFailed:
      name: CampaignFailed
      title: Campaign Failed
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.campaign.failed.v1

    # ─── Connector Messages ───────────────────────────────────────────

    ConnectorCreated:
      name: ConnectorCreated
      title: Connector Created
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.connector.created.v1

    ConnectorSynced:
      name: ConnectorSynced
      title: Connector Sync Completed
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.connector.synced.v1

    ConnectorFailed:
      name: ConnectorFailed
      title: Connector Sync Failed
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.connector.failed.v1

    # ─── Import Messages ──────────────────────────────────────────────

    ImportStarted:
      name: ImportStarted
      title: Import Started
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.import.started.v1

    ImportProgress:
      name: ImportProgress
      title: Import Progress
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.import.progress.v1

    ImportCompleted:
      name: ImportCompleted
      title: Import Completed
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.import.completed.v1

    ImportFailed:
      name: ImportFailed
      title: Import Failed
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.import.failed.v1

    # ─── Staff Messages ───────────────────────────────────────────────

    StaffIncentiveRecorded:
      name: StaffIncentiveRecorded
      title: Staff Incentive Recorded
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'
      x-event-type: com.eventzr.crm.staff.incentive.recorded.v1

    # ─── AI & KG Messages ────────────────────────────────────────────

    AIRequest:
      name: AIRequest
      title: AI Processing Request
      description: |
        Requests sent to aibrain-svc for enrichment, scoring, classification,
        recommendation, sentiment analysis, lead qualification, churn prediction,
        next-best-action, and batch enrichment.
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'

    KGEvent:
      name: KGEvent
      title: Knowledge Graph Projection Event
      description: |
        Node/edge CRUD events, batch projection, similarity requests,
        and taxonomy linkage sent to kg-svc for Neptune synchronization.
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'

    # ─── AI Brain Result (consumed) ──────────────────────────────────

    AIBrainResult:
      name: AIBrainResult
      title: AI Brain Processing Result
      description: Result from aibrain-svc AI processing (scoring, enrichment, classification, etc.)
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'

    # ─── Generic consumed event ──────────────────────────────────────

    GenericCloudEvent:
      name: GenericCloudEvent
      title: CloudEvent (External Service)
      description: Generic CloudEvents 1.0 message from external services
      contentType: application/cloudevents+json
      payload:
        $ref: '#/components/schemas/CloudEventEnvelope'

  schemas:
    CloudEventEnvelope:
      type: object
      required:
        - specversion
        - type
        - source
        - id
        - time
        - datacontenttype
        - data
      properties:
        specversion:
          type: string
          const: '1.0'
          description: CloudEvents specification version
        type:
          type: string
          description: CloudEvent type (e.g. com.eventzr.crm.contact.created.v1)
          example: com.eventzr.crm.contact.created.v1
        source:
          type: string
          description: Service that produced the event
          example: crm-svc
        id:
          type: string
          format: uuid
          description: Unique event identifier
        time:
          type: string
          format: date-time
          description: ISO 8601 timestamp of event creation
        datacontenttype:
          type: string
          const: application/json
        tenantid:
          type: string
          format: uuid
          description: Tenant ID (also used as Kafka partition key)
        data:
          type: object
          description: Event-specific payload
          additionalProperties: true
