asyncapi: '2.6.0'
info:
  title: Domains Service Async API
  version: '2.0.0'
  description: |
    AsyncAPI specification for the EventZR Domains Service (domains-svc).

    This service manages custom domains, DNS configuration, SSL certificates,
    CDN provisioning, dynamic routing, domain transfers, and health monitoring
    for the EventZR multi-tenant event management platform.

    **Event totals: 67 produced, 6 consumed.**

    ## Event Format
    All events follow the **CloudEvents 1.0** specification.

    ### Kafka Headers (on every message)
    | Header          | Description                                        |
    |-----------------|----------------------------------------------------|
    | ce-specversion  | CloudEvents specification version (`1.0`)           |
    | ce-type         | Reverse-DNS event type (e.g. `com.eventzr.domains.domain.registered`) |
    | ce-source       | Producing service (`domains-svc`)                   |
    | ce-id           | Unique event identifier (UUID v4)                   |
    | ce-time         | Event timestamp (ISO 8601)                          |
    | tenant-id       | Tenant identifier for multi-tenant isolation        |

    ### Partition Key
    All messages are partitioned by **tenant_id** to guarantee per-tenant ordering.

    ### Topic Naming Convention
    `eventzr.domains.<entity>.<action>.v<N>`

  contact:
    name: EventZR API Support
    email: api-support@eventzr.com
  license:
    name: Proprietary
    url: https://eventzr.com/terms

servers:
  production:
    url: kafka+ssl://msk.ap-south-1.amazonaws.com:9098
    protocol: kafka-secure
    description: Amazon MSK Serverless - Production (ap-south-1)
    bindings:
      kafka:
        schemaRegistryUrl: https://schema-registry.eventzr.com
  staging:
    url: kafka+ssl://msk-staging.ap-south-1.amazonaws.com:9098
    protocol: kafka-secure
    description: Amazon MSK Serverless - Staging (ap-south-1)
  development:
    url: kafka://localhost:9092
    protocol: kafka
    description: Local development Kafka (Docker Compose)

defaultContentType: application/json

channels:
  # =========================================================================
  # PRODUCED CHANNELS (Outbound - domains-svc publishes)
  # =========================================================================

  # --------------- Domain Lifecycle Events ---------------

  eventzr.domains.domain.registered.v1:
    description: Emitted when a new custom domain is registered by a tenant.
    publish:
      operationId: publishDomainRegistered
      summary: Domain registered
      message:
        $ref: '#/components/messages/DomainRegistered'
      bindings:
        kafka:
          clientId: domains-svc
          groupId: domains-svc-producer

  eventzr.domains.domain.verified.v1:
    description: Emitted when domain ownership verification succeeds (DNS TXT / HTTP challenge).
    publish:
      operationId: publishDomainVerified
      summary: Domain ownership verified
      message:
        $ref: '#/components/messages/DomainVerified'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.verification.failed.v1:
    description: Emitted when domain ownership verification fails.
    publish:
      operationId: publishDomainVerificationFailed
      summary: Domain verification failed
      message:
        $ref: '#/components/messages/DomainVerificationFailed'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.activated.v1:
    description: Emitted when a domain becomes fully active (DNS + SSL + CDN ready).
    publish:
      operationId: publishDomainActivated
      summary: Domain activated
      message:
        $ref: '#/components/messages/DomainActivated'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.suspended.v1:
    description: Emitted when a domain is suspended (payment failure, policy violation, subscription downgrade).
    publish:
      operationId: publishDomainSuspended
      summary: Domain suspended
      message:
        $ref: '#/components/messages/DomainSuspended'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.expired.v1:
    description: Emitted when a domain registration expires.
    publish:
      operationId: publishDomainExpired
      summary: Domain expired
      message:
        $ref: '#/components/messages/DomainExpired'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.expiring.v1:
    description: Emitted when a domain is approaching its expiration date.
    publish:
      operationId: publishDomainExpiring
      summary: Domain expiring soon
      message:
        $ref: '#/components/messages/DomainExpiring'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.deleted.v1:
    description: Emitted when a domain is soft-deleted by a user or system.
    publish:
      operationId: publishDomainDeleted
      summary: Domain deleted
      message:
        $ref: '#/components/messages/DomainDeleted'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.transferred.v1:
    description: Emitted when a domain transfer completes successfully.
    publish:
      operationId: publishDomainTransferred
      summary: Domain transferred
      message:
        $ref: '#/components/messages/DomainTransferred'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.renewed.v1:
    description: Emitted when a domain registration is renewed.
    publish:
      operationId: publishDomainRenewed
      summary: Domain renewed
      message:
        $ref: '#/components/messages/DomainRenewed'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.health.degraded.v1:
    description: Emitted when overall domain health degrades (DNS/SSL/CDN issues detected).
    publish:
      operationId: publishDomainHealthDegraded
      summary: Domain health degraded
      message:
        $ref: '#/components/messages/DomainHealthDegraded'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.whois_privacy.enabled.v1:
    description: Emitted when WHOIS privacy protection is enabled for a domain.
    publish:
      operationId: publishWhoisPrivacyEnabled
      summary: WHOIS privacy enabled
      message:
        $ref: '#/components/messages/WhoisPrivacyEnabled'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.whois_privacy.disabled.v1:
    description: Emitted when WHOIS privacy protection is disabled for a domain.
    publish:
      operationId: publishWhoisPrivacyDisabled
      summary: WHOIS privacy disabled
      message:
        $ref: '#/components/messages/WhoisPrivacyDisabled'
      bindings:
        kafka:
          clientId: domains-svc

  # --------------- Domain-Level SSL Events (from domain.producer.ts) ---------------

  eventzr.domains.domain.ssl.issued.v1:
    description: Emitted when an SSL certificate is successfully issued for a domain (domain-level lifecycle event).
    publish:
      operationId: publishDomainSslIssued
      summary: Domain SSL issued
      message:
        $ref: '#/components/messages/DomainSslIssued'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.ssl.renewed.v1:
    description: Emitted when an SSL certificate is renewed for a domain (domain-level lifecycle event).
    publish:
      operationId: publishDomainSslRenewed
      summary: Domain SSL renewed
      message:
        $ref: '#/components/messages/DomainSslRenewed'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.ssl.failed.v1:
    description: Emitted when SSL certificate issuance or renewal fails for a domain (domain-level lifecycle event).
    publish:
      operationId: publishDomainSslFailed
      summary: Domain SSL failed
      message:
        $ref: '#/components/messages/DomainSslFailed'
      bindings:
        kafka:
          clientId: domains-svc

  # --------------- Domain-Level CDN Events (from domain.producer.ts) ---------------

  eventzr.domains.domain.cdn.provisioned.v1:
    description: Emitted when a CDN distribution is provisioned for a domain (domain-level lifecycle event).
    publish:
      operationId: publishDomainCdnProvisioned
      summary: Domain CDN provisioned
      message:
        $ref: '#/components/messages/DomainCdnProvisioned'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.cdn.updated.v1:
    description: Emitted when a CDN distribution is updated for a domain (domain-level lifecycle event).
    publish:
      operationId: publishDomainCdnUpdated
      summary: Domain CDN updated
      message:
        $ref: '#/components/messages/DomainCdnUpdated'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.cdn.failed.v1:
    description: Emitted when CDN provisioning or update fails for a domain (domain-level lifecycle event).
    publish:
      operationId: publishDomainCdnFailed
      summary: Domain CDN failed
      message:
        $ref: '#/components/messages/DomainCdnFailed'
      bindings:
        kafka:
          clientId: domains-svc

  # --------------- Domain-Level DNS Events (from domain.producer.ts) ---------------

  eventzr.domains.domain.dns.configured.v1:
    description: Emitted when DNS is initially configured for a domain (domain-level lifecycle event).
    publish:
      operationId: publishDomainDnsConfigured
      summary: Domain DNS configured
      message:
        $ref: '#/components/messages/DomainDnsConfigured'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.dns.updated.v1:
    description: Emitted when DNS configuration is updated for a domain (domain-level lifecycle event).
    publish:
      operationId: publishDomainDnsUpdated
      summary: Domain DNS updated
      message:
        $ref: '#/components/messages/DomainDnsUpdated'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.domain.dns.failed.v1:
    description: Emitted when DNS configuration fails for a domain (domain-level lifecycle event).
    publish:
      operationId: publishDomainDnsFailed
      summary: Domain DNS failed
      message:
        $ref: '#/components/messages/DomainDnsFailed'
      bindings:
        kafka:
          clientId: domains-svc

  # --------------- SSL Certificate Events ---------------

  eventzr.domains.ssl.requested.v1:
    description: Emitted when SSL certificate issuance is requested (e.g. ACM or Let's Encrypt).
    publish:
      operationId: publishSslRequested
      summary: SSL certificate requested
      message:
        $ref: '#/components/messages/SslRequested'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.ssl.issued.v1:
    description: Emitted when an SSL certificate is successfully issued and deployed.
    publish:
      operationId: publishSslIssued
      summary: SSL certificate issued
      message:
        $ref: '#/components/messages/SslIssued'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.ssl.renewed.v1:
    description: Emitted when an SSL certificate is successfully renewed.
    publish:
      operationId: publishSslRenewed
      summary: SSL certificate renewed
      message:
        $ref: '#/components/messages/SslRenewed'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.ssl.failed.v1:
    description: Emitted when SSL certificate issuance or renewal fails.
    publish:
      operationId: publishSslFailed
      summary: SSL certificate failed
      message:
        $ref: '#/components/messages/SslFailed'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.ssl.expiring.soon.v1:
    description: Emitted when an SSL certificate is approaching expiration (typically 30 days out).
    publish:
      operationId: publishSslExpiringSoon
      summary: SSL certificate expiring soon
      message:
        $ref: '#/components/messages/SslExpiringSoon'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.ssl.expired.v1:
    description: Emitted when an SSL certificate has expired.
    publish:
      operationId: publishSslExpired
      summary: SSL certificate expired
      message:
        $ref: '#/components/messages/SslExpired'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.ssl.revoked.v1:
    description: Emitted when an SSL certificate is revoked (security incident, key compromise).
    publish:
      operationId: publishSslRevoked
      summary: SSL certificate revoked
      message:
        $ref: '#/components/messages/SslRevoked'
      bindings:
        kafka:
          clientId: domains-svc

  # --------------- CDN Distribution Events ---------------

  eventzr.domains.cdn.provision.requested.v1:
    description: Emitted when CDN distribution provisioning is requested for a domain.
    publish:
      operationId: publishCdnProvisionRequested
      summary: CDN provisioning requested
      message:
        $ref: '#/components/messages/CdnProvisionRequested'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.cdn.provisioned.v1:
    description: Emitted when a CDN distribution is successfully provisioned (CloudFront ready).
    publish:
      operationId: publishCdnProvisioned
      summary: CDN provisioned
      message:
        $ref: '#/components/messages/CdnProvisioned'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.cdn.provision.failed.v1:
    description: Emitted when CDN provisioning fails.
    publish:
      operationId: publishCdnProvisionFailed
      summary: CDN provisioning failed
      message:
        $ref: '#/components/messages/CdnProvisionFailed'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.cdn.updated.v1:
    description: Emitted when a CDN distribution configuration is updated.
    publish:
      operationId: publishCdnUpdated
      summary: CDN configuration updated
      message:
        $ref: '#/components/messages/CdnUpdated'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.cdn.update.failed.v1:
    description: Emitted when a CDN configuration update fails.
    publish:
      operationId: publishCdnUpdateFailed
      summary: CDN update failed
      message:
        $ref: '#/components/messages/CdnUpdateFailed'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.cdn.cache.purged.v1:
    description: Emitted when CDN cache invalidation completes successfully.
    publish:
      operationId: publishCdnCachePurged
      summary: CDN cache purged
      message:
        $ref: '#/components/messages/CdnCachePurged'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.cdn.cache.purge.failed.v1:
    description: Emitted when CDN cache purge fails.
    publish:
      operationId: publishCdnCachePurgeFailed
      summary: CDN cache purge failed
      message:
        $ref: '#/components/messages/CdnCachePurgeFailed'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.cdn.disabled.v1:
    description: Emitted when a CDN distribution is disabled.
    publish:
      operationId: publishCdnDisabled
      summary: CDN distribution disabled
      message:
        $ref: '#/components/messages/CdnDisabled'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.cdn.deleted.v1:
    description: Emitted when a CDN distribution is deleted.
    publish:
      operationId: publishCdnDeleted
      summary: CDN distribution deleted
      message:
        $ref: '#/components/messages/CdnDeleted'
      bindings:
        kafka:
          clientId: domains-svc

  # --------------- DNS Record Events ---------------

  eventzr.domains.dns.record.created.v1:
    description: Emitted when a DNS record is created in the hosted zone.
    publish:
      operationId: publishDnsRecordCreated
      summary: DNS record created
      message:
        $ref: '#/components/messages/DnsRecordCreated'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.dns.record.updated.v1:
    description: Emitted when a DNS record is updated.
    publish:
      operationId: publishDnsRecordUpdated
      summary: DNS record updated
      message:
        $ref: '#/components/messages/DnsRecordUpdated'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.dns.record.deleted.v1:
    description: Emitted when a DNS record is deleted.
    publish:
      operationId: publishDnsRecordDeleted
      summary: DNS record deleted
      message:
        $ref: '#/components/messages/DnsRecordDeleted'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.dns.record.failed.v1:
    description: Emitted when a DNS record operation fails.
    publish:
      operationId: publishDnsRecordFailed
      summary: DNS record operation failed
      message:
        $ref: '#/components/messages/DnsRecordFailed'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.dns.zone.created.v1:
    description: Emitted when a DNS hosted zone is created for a domain.
    publish:
      operationId: publishDnsZoneCreated
      summary: DNS zone created
      message:
        $ref: '#/components/messages/DnsZoneCreated'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.dns.zone.updated.v1:
    description: Emitted when a DNS hosted zone is updated.
    publish:
      operationId: publishDnsZoneUpdated
      summary: DNS zone updated
      message:
        $ref: '#/components/messages/DnsZoneUpdated'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.dns.zone.deleted.v1:
    description: Emitted when a DNS hosted zone is deleted.
    publish:
      operationId: publishDnsZoneDeleted
      summary: DNS zone deleted
      message:
        $ref: '#/components/messages/DnsZoneDeleted'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.dns.propagation.complete.v1:
    description: Emitted when DNS changes have fully propagated across all nameservers.
    publish:
      operationId: publishDnsPropagationComplete
      summary: DNS propagation complete
      message:
        $ref: '#/components/messages/DnsPropagationComplete'
      bindings:
        kafka:
          clientId: domains-svc

  # --------------- Route Events ---------------

  eventzr.domains.route.created.v1:
    description: Emitted when a new route mapping is created for a domain (path -> target service).
    publish:
      operationId: publishRouteCreated
      summary: Route created
      message:
        $ref: '#/components/messages/RouteCreated'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.route.updated.v1:
    description: Emitted when a route mapping is updated (target service or path changed).
    publish:
      operationId: publishRouteUpdated
      summary: Route updated
      message:
        $ref: '#/components/messages/RouteUpdated'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.route.deleted.v1:
    description: Emitted when a route mapping is deleted.
    publish:
      operationId: publishRouteDeleted
      summary: Route deleted
      message:
        $ref: '#/components/messages/RouteDeleted'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.route.activated.v1:
    description: Emitted when a route is activated and begins serving traffic.
    publish:
      operationId: publishRouteActivated
      summary: Route activated
      message:
        $ref: '#/components/messages/RouteActivated'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.route.deactivated.v1:
    description: Emitted when a route is deactivated and stops serving traffic.
    publish:
      operationId: publishRouteDeactivated
      summary: Route deactivated
      message:
        $ref: '#/components/messages/RouteDeactivated'
      bindings:
        kafka:
          clientId: domains-svc

  # --------------- Transfer Events ---------------

  eventzr.domains.transfer.initiated.v1:
    description: Emitted when a domain transfer is initiated between registrars.
    publish:
      operationId: publishTransferInitiated
      summary: Domain transfer initiated
      message:
        $ref: '#/components/messages/TransferInitiated'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.transfer.approved.v1:
    description: Emitted when a domain transfer is approved by the losing registrar.
    publish:
      operationId: publishTransferApproved
      summary: Domain transfer approved
      message:
        $ref: '#/components/messages/TransferApproved'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.transfer.rejected.v1:
    description: Emitted when a domain transfer is rejected.
    publish:
      operationId: publishTransferRejected
      summary: Domain transfer rejected
      message:
        $ref: '#/components/messages/TransferRejected'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.transfer.in_progress.v1:
    description: Emitted when a domain transfer enters the in-progress state.
    publish:
      operationId: publishTransferInProgress
      summary: Domain transfer in progress
      message:
        $ref: '#/components/messages/TransferInProgress'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.transfer.completed.v1:
    description: Emitted when a domain transfer completes successfully.
    publish:
      operationId: publishTransferCompleted
      summary: Domain transfer completed
      message:
        $ref: '#/components/messages/TransferCompleted'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.transfer.failed.v1:
    description: Emitted when a domain transfer fails.
    publish:
      operationId: publishTransferFailed
      summary: Domain transfer failed
      message:
        $ref: '#/components/messages/TransferFailed'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.transfer.cancelled.v1:
    description: Emitted when a domain transfer is cancelled by the user.
    publish:
      operationId: publishTransferCancelled
      summary: Domain transfer cancelled
      message:
        $ref: '#/components/messages/TransferCancelled'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.transfer.expired.v1:
    description: Emitted when a domain transfer expires due to timeout.
    publish:
      operationId: publishTransferExpired
      summary: Domain transfer expired
      message:
        $ref: '#/components/messages/TransferExpired'
      bindings:
        kafka:
          clientId: domains-svc

  # --------------- Health Check Events ---------------

  eventzr.domains.health.checked.v1:
    description: Emitted after a periodic health check is performed on a domain.
    publish:
      operationId: publishHealthChecked
      summary: Domain health checked
      message:
        $ref: '#/components/messages/HealthChecked'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.health.degraded.v1:
    description: Emitted when a domain health check detects degraded performance (high latency, partial failures).
    publish:
      operationId: publishHealthDegraded
      summary: Domain health degraded
      message:
        $ref: '#/components/messages/HealthDegraded'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.health.recovered.v1:
    description: Emitted when a previously degraded or critical domain recovers to a healthy state.
    publish:
      operationId: publishHealthRecovered
      summary: Domain health recovered
      message:
        $ref: '#/components/messages/HealthRecovered'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domains.health.critical.v1:
    description: Emitted when a domain health check detects critical failure (unreachable, SSL invalid).
    publish:
      operationId: publishHealthCritical
      summary: Domain health critical
      message:
        $ref: '#/components/messages/HealthCritical'
      bindings:
        kafka:
          clientId: domains-svc

  # --------------- Custom Domain Events (from custom-domain.service.ts) ---------------

  eventzr.domain.custom_domain.added.v1:
    description: Emitted when a custom domain mapping is added to a tenant portal or event.
    publish:
      operationId: publishCustomDomainAdded
      summary: Custom domain added
      message:
        $ref: '#/components/messages/CustomDomainAdded'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domain.custom_domain.removed.v1:
    description: Emitted when a custom domain mapping is removed from a tenant portal or event.
    publish:
      operationId: publishCustomDomainRemoved
      summary: Custom domain removed
      message:
        $ref: '#/components/messages/CustomDomainRemoved'
      bindings:
        kafka:
          clientId: domains-svc

  eventzr.domain.custom_domain.transferred.v1:
    description: Emitted when a custom domain mapping is transferred to a different portal or event.
    publish:
      operationId: publishCustomDomainTransferred
      summary: Custom domain transferred
      message:
        $ref: '#/components/messages/CustomDomainTransferred'
      bindings:
        kafka:
          clientId: domains-svc

  # --------------- SSL Expiry Alert Events (from ssl-expiry-monitor cron) ---------------

  eventzr.domain.ssl_expiry_alert.v1:
    description: Emitted by the SSL expiry monitoring cron job when certificates are approaching expiration across tenants.
    publish:
      operationId: publishSslExpiryAlert
      summary: SSL expiry alert
      message:
        $ref: '#/components/messages/SslExpiryAlert'
      bindings:
        kafka:
          clientId: domains-svc

  # =========================================================================
  # CONSUMED CHANNELS (Inbound - domains-svc subscribes)
  # =========================================================================

  eventzr.subscriptions.subscription.updated.v1:
    description: |
      Subscription lifecycle events from subscriptions-svc.
      domains-svc consumes these to enforce domain quota limits when
      subscriptions are downgraded or cancelled.
    subscribe:
      operationId: handleSubscriptionEvent
      summary: Handle subscription lifecycle events
      message:
        oneOf:
          - $ref: '#/components/messages/SubscriptionDowngraded'
          - $ref: '#/components/messages/SubscriptionCancelled'
      bindings:
        kafka:
          groupId: domains-svc-subscription-consumer
          clientId: domains-svc

  eventzr.user.tenant.updated.v1:
    description: |
      Tenant lifecycle events from tenant-svc / auth-svc.
      domains-svc consumes these to soft-delete or suspend all domains
      when a tenant is deleted or suspended.
    subscribe:
      operationId: handleTenantEvent
      summary: Handle tenant lifecycle events
      message:
        oneOf:
          - $ref: '#/components/messages/TenantDeleted'
          - $ref: '#/components/messages/TenantSuspended'
      bindings:
        kafka:
          groupId: domains-svc-tenant-consumer
          clientId: domains-svc

  eventzr.wallet.transaction.updated.v1:
    description: |
      Wallet and payment events from wallet-svc.
      domains-svc consumes these to mark domains as failed when
      payments fail or wallet balance is depleted below threshold.
    subscribe:
      operationId: handleWalletEvent
      summary: Handle wallet and payment events
      message:
        oneOf:
          - $ref: '#/components/messages/WalletPaymentFailed'
          - $ref: '#/components/messages/WalletDepleted'
      bindings:
        kafka:
          groupId: domains-svc-wallet-consumer
          clientId: domains-svc

components:
  messages:
    # =============================================
    # DOMAIN LIFECYCLE MESSAGES
    # =============================================

    DomainRegistered:
      name: DomainRegistered
      title: Domain Registered
      summary: A new custom domain has been registered by a tenant user.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainRegisteredCloudEvent'

    DomainVerified:
      name: DomainVerified
      title: Domain Verified
      summary: Domain ownership has been successfully verified via DNS TXT or HTTP challenge.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    DomainVerificationFailed:
      name: DomainVerificationFailed
      title: Domain Verification Failed
      summary: Domain ownership verification has failed.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    DomainActivated:
      name: DomainActivated
      title: Domain Activated
      summary: Domain is fully active with DNS, SSL, and CDN configured.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    DomainSuspended:
      name: DomainSuspended
      title: Domain Suspended
      summary: Domain has been suspended due to payment failure, policy violation, or subscription downgrade.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainSuspendedCloudEvent'

    DomainExpired:
      name: DomainExpired
      title: Domain Expired
      summary: Domain registration has expired.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    DomainExpiring:
      name: DomainExpiring
      title: Domain Expiring Soon
      summary: Domain registration is approaching expiration.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    DomainDeleted:
      name: DomainDeleted
      title: Domain Deleted
      summary: Domain has been soft-deleted by a user or system process.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainRegisteredCloudEvent'

    DomainTransferred:
      name: DomainTransferred
      title: Domain Transferred
      summary: Domain has been transferred to a different registrar or tenant.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainRegisteredCloudEvent'

    DomainRenewed:
      name: DomainRenewed
      title: Domain Renewed
      summary: Domain registration has been renewed for an additional period.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    DomainHealthDegraded:
      name: DomainHealthDegraded
      title: Domain Health Degraded
      summary: Overall domain health has degraded (aggregated from DNS/SSL/CDN checks).
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    WhoisPrivacyEnabled:
      name: WhoisPrivacyEnabled
      title: WHOIS Privacy Enabled
      summary: WHOIS privacy protection has been enabled for a domain.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainRegisteredCloudEvent'

    WhoisPrivacyDisabled:
      name: WhoisPrivacyDisabled
      title: WHOIS Privacy Disabled
      summary: WHOIS privacy protection has been disabled for a domain.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainRegisteredCloudEvent'

    # =============================================
    # DOMAIN-LEVEL SSL MESSAGES (from domain.producer.ts)
    # =============================================

    DomainSslIssued:
      name: DomainSslIssued
      title: Domain SSL Issued
      summary: SSL certificate has been issued for a domain (domain-level lifecycle event).
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    DomainSslRenewed:
      name: DomainSslRenewed
      title: Domain SSL Renewed
      summary: SSL certificate has been renewed for a domain (domain-level lifecycle event).
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    DomainSslFailed:
      name: DomainSslFailed
      title: Domain SSL Failed
      summary: SSL certificate issuance or renewal has failed for a domain (domain-level lifecycle event).
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    # =============================================
    # DOMAIN-LEVEL CDN MESSAGES (from domain.producer.ts)
    # =============================================

    DomainCdnProvisioned:
      name: DomainCdnProvisioned
      title: Domain CDN Provisioned
      summary: CDN distribution has been provisioned for a domain (domain-level lifecycle event).
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    DomainCdnUpdated:
      name: DomainCdnUpdated
      title: Domain CDN Updated
      summary: CDN distribution has been updated for a domain (domain-level lifecycle event).
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    DomainCdnFailed:
      name: DomainCdnFailed
      title: Domain CDN Failed
      summary: CDN provisioning or update has failed for a domain (domain-level lifecycle event).
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    # =============================================
    # DOMAIN-LEVEL DNS MESSAGES (from domain.producer.ts)
    # =============================================

    DomainDnsConfigured:
      name: DomainDnsConfigured
      title: Domain DNS Configured
      summary: DNS has been initially configured for a domain (domain-level lifecycle event).
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    DomainDnsUpdated:
      name: DomainDnsUpdated
      title: Domain DNS Updated
      summary: DNS configuration has been updated for a domain (domain-level lifecycle event).
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    DomainDnsFailed:
      name: DomainDnsFailed
      title: Domain DNS Failed
      summary: DNS configuration has failed for a domain (domain-level lifecycle event).
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DomainLifecycleCloudEvent'

    # =============================================
    # SSL CERTIFICATE MESSAGES
    # =============================================

    SslRequested:
      name: SslRequested
      title: SSL Certificate Requested
      summary: SSL certificate issuance has been requested (ACM / Let's Encrypt).
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/SslBaseCloudEvent'

    SslIssued:
      name: SslIssued
      title: SSL Certificate Issued
      summary: SSL certificate has been successfully issued and deployed.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/SslIssuedCloudEvent'

    SslRenewed:
      name: SslRenewed
      title: SSL Certificate Renewed
      summary: SSL certificate has been successfully renewed.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/SslIssuedCloudEvent'

    SslFailed:
      name: SslFailed
      title: SSL Certificate Failed
      summary: SSL certificate issuance or renewal has failed.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/SslFailedCloudEvent'

    SslExpiringSoon:
      name: SslExpiringSoon
      title: SSL Certificate Expiring Soon
      summary: SSL certificate is approaching expiration (typically 30 days).
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/SslExpiringCloudEvent'

    SslExpired:
      name: SslExpired
      title: SSL Certificate Expired
      summary: SSL certificate has expired.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/SslBaseCloudEvent'

    SslRevoked:
      name: SslRevoked
      title: SSL Certificate Revoked
      summary: SSL certificate has been revoked due to security incident or key compromise.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/SslBaseCloudEvent'

    # =============================================
    # CDN DISTRIBUTION MESSAGES
    # =============================================

    CdnProvisionRequested:
      name: CdnProvisionRequested
      title: CDN Provision Requested
      summary: CDN distribution provisioning has been requested for a domain.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/CdnBaseCloudEvent'

    CdnProvisioned:
      name: CdnProvisioned
      title: CDN Provisioned
      summary: CDN distribution has been successfully provisioned (CloudFront).
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/CdnProvisionedCloudEvent'

    CdnProvisionFailed:
      name: CdnProvisionFailed
      title: CDN Provision Failed
      summary: CDN provisioning has failed.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/CdnFailedCloudEvent'

    CdnUpdated:
      name: CdnUpdated
      title: CDN Updated
      summary: CDN distribution configuration has been updated.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/CdnUpdatedCloudEvent'

    CdnUpdateFailed:
      name: CdnUpdateFailed
      title: CDN Update Failed
      summary: CDN configuration update has failed.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/CdnFailedCloudEvent'

    CdnCachePurged:
      name: CdnCachePurged
      title: CDN Cache Purged
      summary: CDN cache invalidation has completed successfully.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/CdnCachePurgedCloudEvent'

    CdnCachePurgeFailed:
      name: CdnCachePurgeFailed
      title: CDN Cache Purge Failed
      summary: CDN cache purge has failed.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/CdnFailedCloudEvent'

    CdnDisabled:
      name: CdnDisabled
      title: CDN Disabled
      summary: CDN distribution has been disabled.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/CdnDisabledCloudEvent'

    CdnDeleted:
      name: CdnDeleted
      title: CDN Deleted
      summary: CDN distribution has been deleted.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/CdnBaseCloudEvent'

    # =============================================
    # DNS RECORD MESSAGES
    # =============================================

    DnsRecordCreated:
      name: DnsRecordCreated
      title: DNS Record Created
      summary: A DNS record has been created in the hosted zone.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DnsRecordCloudEvent'

    DnsRecordUpdated:
      name: DnsRecordUpdated
      title: DNS Record Updated
      summary: A DNS record has been updated.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DnsRecordCloudEvent'

    DnsRecordDeleted:
      name: DnsRecordDeleted
      title: DNS Record Deleted
      summary: A DNS record has been deleted.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DnsRecordDeletedCloudEvent'

    DnsRecordFailed:
      name: DnsRecordFailed
      title: DNS Record Operation Failed
      summary: A DNS record operation has failed.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DnsRecordFailedCloudEvent'

    DnsZoneCreated:
      name: DnsZoneCreated
      title: DNS Zone Created
      summary: A DNS hosted zone has been created for a domain.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DnsBaseCloudEvent'

    DnsZoneUpdated:
      name: DnsZoneUpdated
      title: DNS Zone Updated
      summary: A DNS hosted zone has been updated.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DnsBaseCloudEvent'

    DnsZoneDeleted:
      name: DnsZoneDeleted
      title: DNS Zone Deleted
      summary: A DNS hosted zone has been deleted.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DnsBaseCloudEvent'

    DnsPropagationComplete:
      name: DnsPropagationComplete
      title: DNS Propagation Complete
      summary: DNS changes have fully propagated across all nameservers.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/DnsBaseCloudEvent'

    # =============================================
    # ROUTE MESSAGES
    # =============================================

    RouteCreated:
      name: RouteCreated
      title: Route Created
      summary: A new route mapping (path to target service) has been created for a domain.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/RouteCloudEvent'

    RouteUpdated:
      name: RouteUpdated
      title: Route Updated
      summary: A route mapping has been updated.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/RouteCloudEvent'

    RouteDeleted:
      name: RouteDeleted
      title: Route Deleted
      summary: A route mapping has been deleted.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/RouteCloudEvent'

    RouteActivated:
      name: RouteActivated
      title: Route Activated
      summary: A route has been activated and is now serving traffic.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/RouteCloudEvent'

    RouteDeactivated:
      name: RouteDeactivated
      title: Route Deactivated
      summary: A route has been deactivated and is no longer serving traffic.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/RouteCloudEvent'

    # =============================================
    # TRANSFER MESSAGES
    # =============================================

    TransferInitiated:
      name: TransferInitiated
      title: Transfer Initiated
      summary: A domain transfer between registrars has been initiated.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/TransferCloudEvent'

    TransferApproved:
      name: TransferApproved
      title: Transfer Approved
      summary: A domain transfer has been approved by the losing registrar.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/TransferCloudEvent'

    TransferRejected:
      name: TransferRejected
      title: Transfer Rejected
      summary: A domain transfer has been rejected.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/TransferCloudEvent'

    TransferInProgress:
      name: TransferInProgress
      title: Transfer In Progress
      summary: A domain transfer is in progress.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/TransferCloudEvent'

    TransferCompleted:
      name: TransferCompleted
      title: Transfer Completed
      summary: A domain transfer has completed successfully.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/TransferCloudEvent'

    TransferFailed:
      name: TransferFailed
      title: Transfer Failed
      summary: A domain transfer has failed.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/TransferFailedCloudEvent'

    TransferCancelled:
      name: TransferCancelled
      title: Transfer Cancelled
      summary: A domain transfer has been cancelled by the user.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/TransferCloudEvent'

    TransferExpired:
      name: TransferExpired
      title: Transfer Expired
      summary: A domain transfer has expired due to timeout.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/TransferCloudEvent'

    # =============================================
    # HEALTH CHECK MESSAGES
    # =============================================

    HealthChecked:
      name: HealthChecked
      title: Health Checked
      summary: A periodic domain health check has been performed.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/HealthCheckCloudEvent'

    HealthDegraded:
      name: HealthDegraded
      title: Health Degraded
      summary: A domain health check has detected degraded performance.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/HealthCheckCloudEvent'

    HealthRecovered:
      name: HealthRecovered
      title: Health Recovered
      summary: A previously degraded domain has recovered to a healthy state.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/HealthCheckCloudEvent'

    HealthCritical:
      name: HealthCritical
      title: Health Critical
      summary: A domain health check has detected critical failure.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/HealthCheckCloudEvent'

    # =============================================
    # CUSTOM DOMAIN MESSAGES (from custom-domain.service.ts)
    # =============================================

    CustomDomainAdded:
      name: CustomDomainAdded
      title: Custom Domain Added
      summary: A custom domain mapping has been added to a tenant portal or event.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/CustomDomainCloudEvent'

    CustomDomainRemoved:
      name: CustomDomainRemoved
      title: Custom Domain Removed
      summary: A custom domain mapping has been removed from a tenant portal or event.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/CustomDomainCloudEvent'

    CustomDomainTransferred:
      name: CustomDomainTransferred
      title: Custom Domain Transferred
      summary: A custom domain mapping has been transferred to a different portal or event.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/CustomDomainCloudEvent'

    # =============================================
    # SSL EXPIRY ALERT MESSAGES (from ssl-expiry-monitor cron)
    # =============================================

    SslExpiryAlert:
      name: SslExpiryAlert
      title: SSL Expiry Alert
      summary: Alert emitted by the SSL expiry monitoring cron job when certificates are approaching expiration.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/SslExpiryAlertCloudEvent'

    # =============================================
    # CONSUMED MESSAGES (from other services)
    # =============================================

    SubscriptionDowngraded:
      name: SubscriptionDowngraded
      title: Subscription Downgraded
      summary: Consumed from subscriptions-svc when a tenant downgrades their subscription tier.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/SubscriptionDowngradedCloudEvent'

    SubscriptionCancelled:
      name: SubscriptionCancelled
      title: Subscription Cancelled
      summary: Consumed from subscriptions-svc when a tenant cancels their subscription.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/SubscriptionCancelledCloudEvent'

    WalletPaymentFailed:
      name: WalletPaymentFailed
      title: Wallet Payment Failed
      summary: Consumed from wallet-svc when a payment fails for a domain-related operation.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/WalletPaymentFailedCloudEvent'

    WalletDepleted:
      name: WalletDepleted
      title: Wallet Depleted
      summary: Consumed from wallet-svc when a tenant wallet balance drops below threshold.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/WalletDepletedCloudEvent'

    TenantDeleted:
      name: TenantDeleted
      title: Tenant Deleted
      summary: Consumed from tenant-svc / auth-svc when a tenant is permanently deleted.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/TenantDeletedCloudEvent'

    TenantSuspended:
      name: TenantSuspended
      title: Tenant Suspended
      summary: Consumed from tenant-svc / auth-svc when a tenant is suspended.
      contentType: application/json
      traits:
        - $ref: '#/components/messageTraits/CloudEventHeaders'
      payload:
        $ref: '#/components/schemas/TenantSuspendedCloudEvent'

  # =============================================
  # SCHEMAS
  # =============================================
  schemas:
    # ----- CloudEvents Envelope -----

    CloudEventEnvelope:
      type: object
      description: CloudEvents 1.0 envelope wrapping all Kafka messages.
      required:
        - specversion
        - type
        - source
        - id
        - time
        - datacontenttype
        - data
      properties:
        specversion:
          type: string
          description: CloudEvents specification version
          const: '1.0'
          example: '1.0'
        type:
          type: string
          description: Reverse-DNS event type (e.g. com.eventzr.domains.domain.registered)
          example: com.eventzr.domains.domain.registered
        source:
          type: string
          description: Service that produced the event
          const: domains-svc
          example: domains-svc
        id:
          type: string
          format: uuid
          description: Unique event identifier (UUID v4)
          example: 550e8400-e29b-41d4-a716-446655440000
        time:
          type: string
          format: date-time
          description: Event timestamp in ISO 8601 format
          example: '2026-02-22T14:30:00.000Z'
        datacontenttype:
          type: string
          description: Content type of the data payload
          const: application/json
        subject:
          type: string
          description: Event subject (resource path)
          example: domain/01ARZ3NDEKTSV4RRFFQ69G5FAV
        tenant_id:
          type: string
          format: uuid
          description: Tenant identifier (also used as Kafka partition key)
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAX
        user_id:
          type: string
          format: uuid
          description: User who triggered the event (empty string if system-initiated)
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAY
        data:
          type: object
          description: Event-specific payload

    # =============================================
    # DOMAIN EVENT SCHEMAS
    # =============================================

    DomainEventData:
      type: object
      description: Base payload for domain lifecycle events.
      required:
        - domain_id
        - tenantId
        - domain
        - status
      properties:
        domain_id:
          type: string
          format: ulid
          description: Unique domain identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAV
        tenantId:
          type: string
          format: uuid
          description: Tenant identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAX
        domain:
          type: string
          description: Fully qualified domain name
          example: myevent.com
        status:
          type: string
          description: Current domain status after this event
          enum:
            - pending
            - verifying
            - verified
            - active
            - suspended
            - expired
            - deleted
            - transferred
            - expiring
            - degraded
        metadata:
          type: object
          description: Additional event-specific metadata
          additionalProperties: true
        user_id:
          type: string
          format: uuid
          description: User who triggered the event (present on user-initiated actions)
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAY

    DomainLifecycleCloudEvent:
      description: CloudEvents 1.0 envelope for domain lifecycle events (no user_id required).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.domain.verified
            subject:
              example: domain/01ARZ3NDEKTSV4RRFFQ69G5FAV
            data:
              $ref: '#/components/schemas/DomainEventData'

    DomainRegisteredCloudEvent:
      description: CloudEvents 1.0 envelope for domain events triggered by a user action.
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.domain.registered
            subject:
              example: domain/01ARZ3NDEKTSV4RRFFQ69G5FAV
            data:
              allOf:
                - $ref: '#/components/schemas/DomainEventData'
                - type: object
                  required:
                    - user_id

    DomainSuspendedCloudEvent:
      description: CloudEvents 1.0 envelope for domain suspension events (includes reason).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.domain.suspended
            data:
              allOf:
                - $ref: '#/components/schemas/DomainEventData'
                - type: object
                  properties:
                    metadata:
                      type: object
                      properties:
                        reason:
                          type: string
                          description: Reason for suspension
                          example: Payment failed

    # =============================================
    # SSL EVENT SCHEMAS
    # =============================================

    SslEventData:
      type: object
      description: Base payload for SSL certificate events.
      required:
        - domain_id
        - tenantId
        - domain
      properties:
        domain_id:
          type: string
          format: ulid
          description: Domain identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAV
        tenantId:
          type: string
          format: uuid
          description: Tenant identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAX
        domain:
          type: string
          description: Domain name
          example: myevent.com
        certificate_id:
          type: string
          description: SSL certificate identifier (ACM ARN or Let's Encrypt serial)
          example: arn:aws:acm:ap-south-1:301858754795:certificate/abc-123
        expires_at:
          type: string
          format: date-time
          description: Certificate expiration date
          example: '2027-02-22T00:00:00.000Z'
        metadata:
          type: object
          description: Additional metadata
          additionalProperties: true

    SslBaseCloudEvent:
      description: CloudEvents 1.0 envelope for basic SSL events.
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.ssl.requested
            subject:
              example: domain/01ARZ3NDEKTSV4RRFFQ69G5FAV/ssl
            data:
              $ref: '#/components/schemas/SslEventData'

    SslIssuedCloudEvent:
      description: CloudEvents 1.0 envelope for SSL issued/renewed events (includes certificate_id and expires_at).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.ssl.issued
            subject:
              example: domain/01ARZ3NDEKTSV4RRFFQ69G5FAV/ssl
            data:
              allOf:
                - $ref: '#/components/schemas/SslEventData'
                - type: object
                  required:
                    - certificate_id
                    - expires_at

    SslFailedCloudEvent:
      description: CloudEvents 1.0 envelope for SSL failure events (includes error in metadata).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.ssl.failed
            data:
              allOf:
                - $ref: '#/components/schemas/SslEventData'
                - type: object
                  properties:
                    metadata:
                      type: object
                      properties:
                        error:
                          type: string
                          description: Error message describing the failure
                          example: DNS validation failed - CNAME record not found

    SslExpiringCloudEvent:
      description: CloudEvents 1.0 envelope for SSL expiring soon events (includes days_remaining).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.ssl.expiring.soon
            data:
              allOf:
                - $ref: '#/components/schemas/SslEventData'
                - type: object
                  required:
                    - certificate_id
                    - expires_at
                  properties:
                    metadata:
                      type: object
                      properties:
                        days_remaining:
                          type: integer
                          description: Number of days until certificate expires
                          example: 30

    # =============================================
    # CDN EVENT SCHEMAS
    # =============================================

    CdnEventData:
      type: object
      description: Base payload for CDN distribution events.
      required:
        - domain_id
        - tenantId
        - domain
      properties:
        domain_id:
          type: string
          format: ulid
          description: Domain identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAV
        tenantId:
          type: string
          format: uuid
          description: Tenant identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAX
        domain:
          type: string
          description: Domain name
          example: myevent.com
        cdn_distribution_id:
          type: string
          description: CloudFront distribution identifier
          example: E1234ABCD5678
        metadata:
          type: object
          description: Additional metadata
          additionalProperties: true

    CdnBaseCloudEvent:
      description: CloudEvents 1.0 envelope for basic CDN events.
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.cdn.provision.requested
            subject:
              example: domain/01ARZ3NDEKTSV4RRFFQ69G5FAV/cdn
            data:
              $ref: '#/components/schemas/CdnEventData'

    CdnProvisionedCloudEvent:
      description: CloudEvents 1.0 envelope for CDN provisioned events (includes distribution ID).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.cdn.provisioned
            data:
              allOf:
                - $ref: '#/components/schemas/CdnEventData'
                - type: object
                  required:
                    - cdn_distribution_id

    CdnFailedCloudEvent:
      description: CloudEvents 1.0 envelope for CDN failure events (includes error in metadata).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.cdn.provision.failed
            data:
              allOf:
                - $ref: '#/components/schemas/CdnEventData'
                - type: object
                  properties:
                    metadata:
                      type: object
                      properties:
                        error:
                          type: string
                          description: Error message describing the failure
                          example: CloudFront distribution limit reached

    CdnUpdatedCloudEvent:
      description: CloudEvents 1.0 envelope for CDN updated events (includes changes in metadata).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.cdn.updated
            data:
              allOf:
                - $ref: '#/components/schemas/CdnEventData'
                - type: object
                  required:
                    - cdn_distribution_id
                  properties:
                    metadata:
                      type: object
                      properties:
                        changes:
                          type: object
                          description: Configuration changes applied
                          additionalProperties: true

    CdnCachePurgedCloudEvent:
      description: CloudEvents 1.0 envelope for CDN cache purged events (includes purged paths).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.cdn.cache.purged
            data:
              allOf:
                - $ref: '#/components/schemas/CdnEventData'
                - type: object
                  required:
                    - cdn_distribution_id
                  properties:
                    metadata:
                      type: object
                      properties:
                        paths:
                          type: array
                          items:
                            type: string
                          description: Cache paths that were invalidated
                          example: ['/*', '/assets/*']

    CdnDisabledCloudEvent:
      description: CloudEvents 1.0 envelope for CDN disabled events (includes reason).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.cdn.disabled
            data:
              allOf:
                - $ref: '#/components/schemas/CdnEventData'
                - type: object
                  required:
                    - cdn_distribution_id
                  properties:
                    metadata:
                      type: object
                      properties:
                        reason:
                          type: string
                          description: Reason for disabling CDN
                          example: Domain suspended

    # =============================================
    # DNS EVENT SCHEMAS
    # =============================================

    DnsEventData:
      type: object
      description: Base payload for DNS events.
      required:
        - domain_id
        - tenantId
        - domain
      properties:
        domain_id:
          type: string
          format: ulid
          description: Domain identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAV
        tenantId:
          type: string
          format: uuid
          description: Tenant identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAX
        domain:
          type: string
          description: Domain name
          example: myevent.com
        record_type:
          type: string
          description: DNS record type
          enum: [A, AAAA, CNAME, MX, TXT, NS, SRV, CAA]
        record_name:
          type: string
          description: Record name/subdomain
          example: www
        record_value:
          type: string
          description: Record value
          example: 192.168.1.1
        metadata:
          type: object
          description: Additional metadata
          additionalProperties: true

    DnsBaseCloudEvent:
      description: CloudEvents 1.0 envelope for basic DNS events (zone-level operations).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.dns.zone.created
            subject:
              example: domain/01ARZ3NDEKTSV4RRFFQ69G5FAV/dns
            data:
              $ref: '#/components/schemas/DnsEventData'

    DnsRecordCloudEvent:
      description: CloudEvents 1.0 envelope for DNS record CRUD events (includes record details).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.dns.record.created
            subject:
              example: domain/01ARZ3NDEKTSV4RRFFQ69G5FAV/dns
            data:
              allOf:
                - $ref: '#/components/schemas/DnsEventData'
                - type: object
                  required:
                    - record_type
                    - record_name
                    - record_value

    DnsRecordDeletedCloudEvent:
      description: CloudEvents 1.0 envelope for DNS record deleted events (no record_value).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.dns.record.deleted
            data:
              allOf:
                - $ref: '#/components/schemas/DnsEventData'
                - type: object
                  required:
                    - record_type
                    - record_name

    DnsRecordFailedCloudEvent:
      description: CloudEvents 1.0 envelope for DNS record failure events (includes error).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.dns.record.failed
            data:
              allOf:
                - $ref: '#/components/schemas/DnsEventData'
                - type: object
                  required:
                    - record_type
                    - record_name
                  properties:
                    metadata:
                      type: object
                      properties:
                        error:
                          type: string
                          description: Error message describing the failure
                          example: Record conflict - CNAME already exists

    # =============================================
    # ROUTE EVENT SCHEMAS
    # =============================================

    RouteEventData:
      type: object
      description: Payload for route mapping events.
      required:
        - route_id
        - domain_id
        - tenantId
        - path
        - target_service
      properties:
        route_id:
          type: string
          format: ulid
          description: Route mapping identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FBB
        domain_id:
          type: string
          format: ulid
          description: Domain identifier the route belongs to
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAV
        tenantId:
          type: string
          format: uuid
          description: Tenant identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAX
        path:
          type: string
          description: URL path pattern for the route
          example: /api/v1/*
        target_service:
          type: string
          description: Target backend service for this route
          example: event-svc
        metadata:
          type: object
          description: Additional metadata (priority, headers, etc.)
          additionalProperties: true
        user_id:
          type: string
          format: uuid
          description: User who created/modified the route
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAY

    RouteCloudEvent:
      description: CloudEvents 1.0 envelope for route mapping events.
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.route.created
            subject:
              example: domain/01ARZ3NDEKTSV4RRFFQ69G5FAV/route/01ARZ3NDEKTSV4RRFFQ69G5FBB
            data:
              $ref: '#/components/schemas/RouteEventData'

    # =============================================
    # TRANSFER EVENT SCHEMAS
    # =============================================

    TransferEventData:
      type: object
      description: Payload for domain transfer events.
      required:
        - transfer_id
        - domain_id
        - domain
        - tenantId
        - from_registrar
        - to_registrar
        - status
      properties:
        transfer_id:
          type: string
          format: ulid
          description: Transfer tracking identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FCC
        domain_id:
          type: string
          format: ulid
          description: Domain identifier being transferred
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAV
        domain:
          type: string
          description: Domain name being transferred
          example: myevent.com
        tenantId:
          type: string
          format: uuid
          description: Tenant identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAX
        from_registrar:
          type: string
          description: Source registrar
          example: GoDaddy
        to_registrar:
          type: string
          description: Target registrar
          example: Route53
        status:
          type: string
          description: Current transfer status
          enum:
            - INITIATED
            - APPROVED
            - REJECTED
            - IN_PROGRESS
            - COMPLETED
            - FAILED
            - CANCELLED
            - EXPIRED
        metadata:
          type: object
          description: Additional metadata
          additionalProperties: true
        user_id:
          type: string
          format: uuid
          description: User who initiated the transfer
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAY

    TransferCloudEvent:
      description: CloudEvents 1.0 envelope for domain transfer events.
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.transfer.initiated
            subject:
              example: domain/01ARZ3NDEKTSV4RRFFQ69G5FAV/transfer/01ARZ3NDEKTSV4RRFFQ69G5FCC
            data:
              $ref: '#/components/schemas/TransferEventData'

    TransferFailedCloudEvent:
      description: CloudEvents 1.0 envelope for transfer failure events (includes failure_reason).
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.transfer.failed
            data:
              allOf:
                - $ref: '#/components/schemas/TransferEventData'
                - type: object
                  properties:
                    metadata:
                      type: object
                      properties:
                        failure_reason:
                          type: string
                          description: Reason the transfer failed
                          example: Auth code invalid or expired

    # =============================================
    # HEALTH CHECK EVENT SCHEMAS
    # =============================================

    HealthCheckEventData:
      type: object
      description: Payload for domain health check events.
      required:
        - health_check_id
        - domain_id
        - domain
        - tenantId
        - status
      properties:
        health_check_id:
          type: string
          format: ulid
          description: Health check run identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FDD
        domain_id:
          type: string
          format: ulid
          description: Domain identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAV
        domain:
          type: string
          description: Domain name
          example: myevent.com
        tenantId:
          type: string
          format: uuid
          description: Tenant identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAX
        status:
          type: string
          description: Health check result status
          enum:
            - healthy
            - degraded
            - critical
            - unreachable
        latency_ms:
          type: number
          description: Response latency in milliseconds
          example: 142
        metadata:
          type: object
          description: Additional health check details (DNS resolution time, SSL validity, etc.)
          additionalProperties: true

    HealthCheckCloudEvent:
      description: CloudEvents 1.0 envelope for health check events.
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domains.health.checked
            subject:
              example: domain/01ARZ3NDEKTSV4RRFFQ69G5FAV/health
            data:
              $ref: '#/components/schemas/HealthCheckEventData'

    # =============================================
    # CUSTOM DOMAIN EVENT SCHEMAS
    # =============================================

    CustomDomainEventData:
      type: object
      description: Payload for custom domain mapping events.
      required:
        - domain_id
        - tenantId
        - domain
        - target_type
        - target_id
      properties:
        domain_id:
          type: string
          format: ulid
          description: Domain identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAV
        tenantId:
          type: string
          format: uuid
          description: Tenant identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAX
        domain:
          type: string
          description: Fully qualified domain name
          example: events.mycompany.com
        target_type:
          type: string
          description: Type of target the custom domain maps to
          enum:
            - portal
            - event
            - landing_page
          example: portal
        target_id:
          type: string
          format: ulid
          description: Identifier of the target resource
          example: 01ARZ3NDEKTSV4RRFFQ69G5FEE
        metadata:
          type: object
          description: Additional metadata
          additionalProperties: true
        user_id:
          type: string
          format: uuid
          description: User who performed the action
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAY

    CustomDomainCloudEvent:
      description: CloudEvents 1.0 envelope for custom domain mapping events.
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domain.custom_domain.added
            subject:
              example: domain/01ARZ3NDEKTSV4RRFFQ69G5FAV/custom-domain
            data:
              $ref: '#/components/schemas/CustomDomainEventData'

    # =============================================
    # SSL EXPIRY ALERT EVENT SCHEMAS
    # =============================================

    SslExpiryAlertEventData:
      type: object
      description: Payload for SSL expiry alert events emitted by the monitoring cron job.
      required:
        - domain_id
        - tenantId
        - domain
        - certificate_id
        - expires_at
        - days_remaining
      properties:
        domain_id:
          type: string
          format: ulid
          description: Domain identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAV
        tenantId:
          type: string
          format: uuid
          description: Tenant identifier
          example: 01ARZ3NDEKTSV4RRFFQ69G5FAX
        domain:
          type: string
          description: Domain name with expiring certificate
          example: myevent.com
        certificate_id:
          type: string
          description: SSL certificate identifier (ACM ARN or Let's Encrypt serial)
          example: arn:aws:acm:ap-south-1:301858754795:certificate/abc-123
        expires_at:
          type: string
          format: date-time
          description: Certificate expiration date
          example: '2026-03-22T00:00:00.000Z'
        days_remaining:
          type: integer
          description: Number of days until certificate expires
          example: 28
        severity:
          type: string
          description: Alert severity level based on days remaining
          enum:
            - warning
            - critical
          example: warning
        metadata:
          type: object
          description: Additional metadata
          additionalProperties: true

    SslExpiryAlertCloudEvent:
      description: CloudEvents 1.0 envelope for SSL expiry alert events from the monitoring cron job.
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: com.eventzr.domain.ssl_expiry_alert
            subject:
              example: domain/01ARZ3NDEKTSV4RRFFQ69G5FAV/ssl/expiry-alert
            data:
              $ref: '#/components/schemas/SslExpiryAlertEventData'

    # =============================================
    # CONSUMED EVENT SCHEMAS (from other services)
    # =============================================

    SubscriptionDowngradedCloudEvent:
      description: CloudEvents 1.0 envelope for subscription downgraded events from subscriptions-svc.
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: subscription.downgraded
            source:
              example: subscriptions-svc
            data:
              type: object
              required:
                - tenantId
                - old_tier
                - new_tier
                - old_quotas
                - new_quotas
              properties:
                tenantId:
                  type: string
                  format: uuid
                  description: Tenant identifier
                old_tier:
                  type: string
                  description: Previous subscription tier
                  example: startup
                new_tier:
                  type: string
                  description: New (lower) subscription tier
                  example: student
                old_quotas:
                  type: object
                  properties:
                    max_custom_domains:
                      type: integer
                      description: Previous max custom domains quota
                      example: 10
                new_quotas:
                  type: object
                  properties:
                    max_custom_domains:
                      type: integer
                      description: New max custom domains quota
                      example: 3

    SubscriptionCancelledCloudEvent:
      description: CloudEvents 1.0 envelope for subscription cancelled events from subscriptions-svc.
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: subscription.cancelled
            source:
              example: subscriptions-svc
            data:
              type: object
              required:
                - tenantId
                - tier
                - cancelled_at
              properties:
                tenantId:
                  type: string
                  format: uuid
                  description: Tenant identifier
                tier:
                  type: string
                  description: Cancelled subscription tier
                  example: pro
                cancelled_at:
                  type: string
                  format: date-time
                  description: Cancellation timestamp
                  example: '2026-02-22T14:30:00.000Z'

    WalletPaymentFailedCloudEvent:
      description: CloudEvents 1.0 envelope for wallet payment failed events from wallet-svc.
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: wallet.payment.failed
            source:
              example: wallet-svc
            data:
              type: object
              required:
                - tenantId
                - transaction_id
                - amount
                - reason
              properties:
                tenantId:
                  type: string
                  format: uuid
                  description: Tenant identifier
                transaction_id:
                  type: string
                  format: uuid
                  description: Failed transaction identifier
                  example: 550e8400-e29b-41d4-a716-446655440001
                amount:
                  type: number
                  format: float
                  description: Transaction amount that failed
                  example: 12.99
                reason:
                  type: string
                  description: Payment failure reason
                  example: Insufficient funds
                metadata:
                  type: object
                  properties:
                    domain_id:
                      type: string
                      format: ulid
                      description: Associated domain ID (if domain-related payment)
                    domain:
                      type: string
                      description: Associated domain name (if domain-related payment)

    WalletDepletedCloudEvent:
      description: CloudEvents 1.0 envelope for wallet depleted events from wallet-svc.
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: wallet.depleted
            source:
              example: wallet-svc
            data:
              type: object
              required:
                - tenantId
                - balance
                - threshold
              properties:
                tenantId:
                  type: string
                  format: uuid
                  description: Tenant identifier
                balance:
                  type: number
                  format: float
                  description: Current wallet balance
                  example: 0.50
                threshold:
                  type: number
                  format: float
                  description: Depletion threshold that was crossed
                  example: 5.00

    TenantDeletedCloudEvent:
      description: CloudEvents 1.0 envelope for tenant deleted events from tenant-svc / auth-svc.
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: tenant.deleted
            source:
              example: auth-svc
            data:
              type: object
              required:
                - tenantId
                - deleted_at
                - deleted_by
              properties:
                tenantId:
                  type: string
                  format: uuid
                  description: Deleted tenant identifier
                deleted_at:
                  type: string
                  format: date-time
                  description: Deletion timestamp
                  example: '2026-02-22T14:30:00.000Z'
                deleted_by:
                  type: string
                  format: uuid
                  description: User who performed the deletion
                  example: 01ARZ3NDEKTSV4RRFFQ69G5FAY

    TenantSuspendedCloudEvent:
      description: CloudEvents 1.0 envelope for tenant suspended events from tenant-svc / auth-svc.
      allOf:
        - $ref: '#/components/schemas/CloudEventEnvelope'
        - type: object
          properties:
            type:
              example: tenant.suspended
            source:
              example: auth-svc
            data:
              type: object
              required:
                - tenantId
                - suspended_at
                - reason
              properties:
                tenantId:
                  type: string
                  format: uuid
                  description: Suspended tenant identifier
                suspended_at:
                  type: string
                  format: date-time
                  description: Suspension timestamp
                  example: '2026-02-22T14:30:00.000Z'
                reason:
                  type: string
                  description: Reason for suspension
                  example: Terms of service violation

  # =============================================
  # MESSAGE TRAITS
  # =============================================
  messageTraits:
    CloudEventHeaders:
      headers:
        type: object
        description: |
          CloudEvents 1.0 protocol headers sent as Kafka message headers.
          These headers are present on every message in addition to the
          CloudEvents attributes in the message body.
        required:
          - ce-specversion
          - ce-type
          - ce-source
          - ce-id
          - ce-time
          - tenant-id
        properties:
          ce-specversion:
            type: string
            description: CloudEvents specification version
            const: '1.0'
          ce-type:
            type: string
            description: Event type (reverse-DNS format for produced events)
            example: com.eventzr.domains.domain.registered
          ce-source:
            type: string
            description: Service that produced the event
            example: domains-svc
          ce-id:
            type: string
            format: uuid
            description: Unique event identifier (UUID v4)
            example: 550e8400-e29b-41d4-a716-446655440000
          ce-time:
            type: string
            format: date-time
            description: Event timestamp in ISO 8601 format
            example: '2026-02-22T14:30:00.000Z'
          tenant-id:
            type: string
            format: uuid
            description: |
              Tenant identifier for multi-tenant isolation.
              Also used as the Kafka partition key to guarantee per-tenant ordering.
            example: 01ARZ3NDEKTSV4RRFFQ69G5FAX
      bindings:
        kafka:
          key:
            type: string
            description: Kafka partition key (always tenant_id for per-tenant ordering)

tags:
  - name: Domain Events
    description: Events related to domain lifecycle (registration, verification, activation, expiration, deletion, SSL/CDN/DNS sub-events)
  - name: SSL Events
    description: Events related to SSL certificate lifecycle (request, issuance, renewal, expiration, revocation)
  - name: CDN Events
    description: Events related to CDN distribution lifecycle (provisioning, updates, cache purge, disabling)
  - name: DNS Events
    description: Events related to DNS record and zone management (CRUD operations, propagation)
  - name: Route Events
    description: Events related to domain route mappings (path-to-service routing rules)
  - name: Transfer Events
    description: Events related to domain transfers between registrars
  - name: Health Events
    description: Events related to periodic domain health monitoring
  - name: Custom Domain Events
    description: Events related to custom domain mappings for tenant portals and events
  - name: SSL Expiry Alert Events
    description: Events emitted by the SSL expiry monitoring cron job
  - name: Consumed Events
    description: Events consumed from external services (subscriptions-svc, wallet-svc, tenant-svc)
