asyncapi: '2.6.0'
info:
  title: webify-svc Async API
  version: '2.0.0'
  description: |
    Kafka event specifications for the EventZR Website Builder Service (webify-svc).
    All events follow CloudEvents 1.0 specification and are partitioned by tenant_id.

    This specification covers:
    - **Produced events** (publish): Events emitted by webify-svc to notify other services
    - **Consumed events** (subscribe): Events consumed by webify-svc from other services
  contact:
    name: EventZR Team
    email: support@eventzr.com

servers:
  staging:
    url: boot-gpm4u49z.c2.kafka-serverless.us-east-1.amazonaws.com:9098
    protocol: kafka
    description: Amazon MSK Serverless (Staging, us-east-1, IAM auth)
  localhost:
    url: localhost:9092
    protocol: kafka
    description: Local Kafka (Docker)

defaultContentType: application/cloudevents+json

channels:
  # ============================================================================
  # PRODUCED EVENTS (webify-svc publishes these)
  # ============================================================================

  # --- Page Events ---

  eventzr.webify.page.created.v1:
    description: Emitted when a new landing page is created.
    publish:
      operationId: onPageCreated
      summary: Page Created
      message:
        $ref: '#/components/messages/PageCreatedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  eventzr.webify.page.published.v1:
    description: Emitted when a page is published to staging or production.
    publish:
      operationId: onPagePublished
      summary: Page Published
      message:
        $ref: '#/components/messages/PagePublishedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  # --- Template Events ---

  eventzr.webify.template.created.v1:
    description: Emitted when a new template is created.
    publish:
      operationId: onTemplateCreated
      summary: Template Created
      message:
        $ref: '#/components/messages/TemplateCreatedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID) or "platform" for platform templates

  eventzr.webify.template.updated.v1:
    description: Emitted when a template is updated.
    publish:
      operationId: onTemplateUpdated
      summary: Template Updated
      message:
        $ref: '#/components/messages/TemplateUpdatedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID) or "platform" for platform templates

  eventzr.webify.template.purchased.v1:
    description: Emitted when a template is purchased from the marketplace.
    publish:
      operationId: onTemplatePurchased
      summary: Template Purchased
      message:
        $ref: '#/components/messages/TemplatePurchasedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: buyer_tenant_id (UUID)

  # --- Theme Events ---

  eventzr.webify.theme.created.v1:
    description: Emitted when a new theme is created.
    publish:
      operationId: onThemeCreated
      summary: Theme Created
      message:
        $ref: '#/components/messages/ThemeCreatedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID) or "platform" for platform themes

  eventzr.webify.theme.updated.v1:
    description: Emitted when a theme is updated.
    publish:
      operationId: onThemeUpdated
      summary: Theme Updated
      message:
        $ref: '#/components/messages/ThemeUpdatedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID) or "platform" for platform themes

  eventzr.webify.theme.applied.v1:
    description: Emitted when a theme is applied to a page.
    publish:
      operationId: onThemeApplied
      summary: Theme Applied
      message:
        $ref: '#/components/messages/ThemeAppliedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  # --- Domain Events ---

  eventzr.webify.domain.registered.v1:
    description: Emitted when a custom domain is registered for a page.
    publish:
      operationId: onDomainRegistered
      summary: Domain Registered
      message:
        $ref: '#/components/messages/DomainRegisteredEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  eventzr.webify.domain.verified.v1:
    description: Emitted when a custom domain is successfully verified.
    publish:
      operationId: onDomainVerified
      summary: Domain Verified
      message:
        $ref: '#/components/messages/DomainVerifiedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  eventzr.webify.domain.failed.v1:
    description: Emitted when domain verification or setup fails.
    publish:
      operationId: onDomainFailed
      summary: Domain Failed
      message:
        $ref: '#/components/messages/DomainFailedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  # --- A/B Test Events ---

  eventzr.webify.abtest.started.v1:
    description: Emitted when an A/B test is started.
    publish:
      operationId: onABTestStarted
      summary: A/B Test Started
      message:
        $ref: '#/components/messages/ABTestStartedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  eventzr.webify.abtest.completed.v1:
    description: Emitted when an A/B test is completed (stopped with results).
    publish:
      operationId: onABTestCompleted
      summary: A/B Test Completed
      message:
        $ref: '#/components/messages/ABTestCompletedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  # --- Comment Events ---

  eventzr.webify.comment.created.v1:
    description: Emitted when a new comment is added to a page section.
    publish:
      operationId: onCommentCreated
      summary: Comment Created
      message:
        $ref: '#/components/messages/CommentCreatedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  eventzr.webify.comment.updated.v1:
    description: Emitted when a comment is edited.
    publish:
      operationId: onCommentUpdated
      summary: Comment Updated
      message:
        $ref: '#/components/messages/CommentUpdatedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  eventzr.webify.comment.deleted.v1:
    description: Emitted when a comment is deleted.
    publish:
      operationId: onCommentDeleted
      summary: Comment Deleted
      message:
        $ref: '#/components/messages/CommentDeletedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  eventzr.webify.comment.resolved.v1:
    description: Emitted when a comment thread is resolved.
    publish:
      operationId: onCommentResolved
      summary: Comment Resolved
      message:
        $ref: '#/components/messages/CommentResolvedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  eventzr.webify.comment.mentioned.v1:
    description: Emitted when a user is @mentioned in a comment (triggers notification).
    publish:
      operationId: onCommentMentioned
      summary: Comment Mention
      message:
        $ref: '#/components/messages/CommentMentionedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  # --- Profile Template Events ---

  eventzr.webify.profile_template.applied.v1:
    description: Emitted when a profile template is applied to a page.
    publish:
      operationId: onProfileTemplateApplied
      summary: Profile Template Applied
      message:
        $ref: '#/components/messages/ProfileTemplateAppliedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  eventzr.webify.profile_template.customized.v1:
    description: Emitted when a profile template section is customized.
    publish:
      operationId: onProfileTemplateCustomized
      summary: Profile Template Customized
      message:
        $ref: '#/components/messages/ProfileTemplateCustomizedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  eventzr.webify.profile_template.preference_updated.v1:
    description: Emitted when profile template preferences (enabled sections, order, theme) are updated.
    publish:
      operationId: onProfileTemplatePreferenceUpdated
      summary: Profile Template Preference Updated
      message:
        $ref: '#/components/messages/ProfileTemplatePreferenceUpdatedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  eventzr.webify.profile_template.removed.v1:
    description: Emitted when a profile template is removed from a page.
    publish:
      operationId: onProfileTemplateRemoved
      summary: Profile Template Removed
      message:
        $ref: '#/components/messages/ProfileTemplateRemovedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: tenant_id (UUID)

  # --- Template Query Events (Request/Response via Kafka) ---

  eventzr.webify.template.query.requested.v1:
    description: |
      Consumed by webify-svc from AIBuilderModule. Triggers a template query
      and emits a response event with correlated results.
    subscribe:
      operationId: handleTemplateQueryRequested
      summary: Template Query Requested (consumed via EventEmitter)
      message:
        $ref: '#/components/messages/TemplateQueryRequestedEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: correlation_id

  eventzr.webify.template.query.response.v1:
    description: |
      Emitted by webify-svc in response to a template.query.requested event.
      Contains the matching templates, keyed by correlation ID for request-response matching.
    publish:
      operationId: onTemplateQueryResponse
      summary: Template Query Response
      message:
        $ref: '#/components/messages/TemplateQueryResponseEvent'
    bindings:
      kafka:
        partitions: 6
        replicas: 3
        key:
          type: string
          description: correlation_id (matches the requesting event)

  # ============================================================================
  # CONSUMED EVENTS (webify-svc subscribes to these from other services)
  # ============================================================================

  # --- Wallet Events (from wallet-svc) ---

  eventzr.wallet.credit.deducted.v1:
    description: |
      Consumed from wallet-svc. When credits are deducted for webify operations
      (AI page generation, template purchases), the cached credit balance is
      invalidated and an audit log entry is created.
    subscribe:
      operationId: handleCreditDeducted
      summary: Credit Deducted
      message:
        $ref: '#/components/messages/CreditDeductedEvent'
    bindings:
      kafka:
        groupId: webify-svc-wallet-consumer
        key:
          type: string
          description: tenant_id (UUID)

  eventzr.wallet.credit.refunded.v1:
    description: |
      Consumed from wallet-svc. When credits are refunded (e.g. failed AI generation),
      the cached credit balance is invalidated and an audit log entry is created.
    subscribe:
      operationId: handleCreditRefunded
      summary: Credit Refunded
      message:
        $ref: '#/components/messages/CreditRefundedEvent'
    bindings:
      kafka:
        groupId: webify-svc-wallet-consumer
        key:
          type: string
          description: tenant_id (UUID)

  # --- Domain Events (from domains-svc) ---

  eventzr.domains.ssl.issued.v1:
    description: |
      Consumed from domains-svc. When a new SSL certificate is issued for a custom
      domain, webify-svc invalidates cached domain status and creates an audit log entry.
    subscribe:
      operationId: handleSSLIssued
      summary: SSL Certificate Issued
      message:
        $ref: '#/components/messages/SSLIssuedEvent'
    bindings:
      kafka:
        groupId: webify-svc-domain-consumer
        key:
          type: string
          description: tenant_id (UUID)

  eventzr.domains.ssl.expiring.v1:
    description: |
      Consumed from domains-svc. When an SSL certificate is approaching expiry,
      webify-svc logs a warning, invalidates caches, and creates an audit entry
      visible in the admin dashboard.
    subscribe:
      operationId: handleSSLExpiring
      summary: SSL Certificate Expiring
      message:
        $ref: '#/components/messages/SSLExpiringEvent'
    bindings:
      kafka:
        groupId: webify-svc-domain-consumer
        key:
          type: string
          description: tenant_id (UUID)

  # --- CMS Events (from cms-svc) ---

  eventzr.cms.content.updated.v1:
    description: |
      Consumed from cms-svc. When CMS content is updated, webify-svc invalidates
      page caches referencing the content and triggers a media asset sync.
    subscribe:
      operationId: handleContentUpdated
      summary: CMS Content Updated
      message:
        $ref: '#/components/messages/ContentUpdatedEvent'
    bindings:
      kafka:
        groupId: webify-svc-cms-consumer
        key:
          type: string
          description: tenant_id (UUID)

  eventzr.cms.media.uploaded.v1:
    description: |
      Consumed from cms-svc. When new media is uploaded, webify-svc invalidates
      media-related caches for the tenant.
    subscribe:
      operationId: handleMediaUploaded
      summary: CMS Media Uploaded
      message:
        $ref: '#/components/messages/MediaUploadedEvent'
    bindings:
      kafka:
        groupId: webify-svc-cms-consumer
        key:
          type: string
          description: tenant_id (UUID)

  # --- Taxonomy Events (from taxonomy-svc) ---

  eventzr.taxonomy.category.updated.v1:
    description: |
      Consumed from taxonomy-svc. When a taxonomy category is updated, webify-svc
      invalidates template taxonomy caches so browse/filter endpoints return fresh data.
    subscribe:
      operationId: handleCategoryUpdated
      summary: Taxonomy Category Updated
      message:
        $ref: '#/components/messages/CategoryUpdatedEvent'
    bindings:
      kafka:
        groupId: webify-svc-taxonomy-consumer
        key:
          type: string
          description: tenant_id (UUID)

components:
  messages:
    # ==========================================================================
    # PRODUCED MESSAGE SCHEMAS
    # ==========================================================================

    # --- Page Messages ---

    PageCreatedEvent:
      name: PageCreatedEvent
      title: Page Created
      contentType: application/cloudevents+json
      headers:
        type: object
        properties:
          ce_id:
            type: string
            format: uuid
          ce_source:
            type: string
            example: eventzr/webify-svc
          ce_type:
            type: string
            example: eventzr.webify.page.created.v1
          ce_specversion:
            type: string
            example: '1.0'
          ce_tenantid:
            type: string
            format: uuid
          idempotency-key:
            type: string
            description: SHA256-based idempotency key
      payload:
        type: object
        properties:
          page_id:
            type: string
            format: uuid
          tenant_id:
            type: string
            format: uuid
          title:
            type: string
          slug:
            type: string
          entity_type:
            type: string
            enum: [event, tour, venue, destination, brand, campaign, profile, generic]
          entity_id:
            type: string
            format: uuid
            nullable: true
          template_id:
            type: string
            format: uuid
            nullable: true
          theme_id:
            type: string
            format: uuid
            nullable: true
          status:
            type: string
            enum: [draft, published_staging, published_production, archived]
          created_by:
            type: string
            format: uuid
          created_at:
            type: string
            format: date-time

    PagePublishedEvent:
      name: PagePublishedEvent
      title: Page Published
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          page_id:
            type: string
            format: uuid
          tenant_id:
            type: string
            format: uuid
          title:
            type: string
          slug:
            type: string
          environment:
            type: string
            enum: [staging, production]
          published_url:
            type: string
            format: uri
          version:
            type: integer
          published_by:
            type: string
            format: uuid
          published_at:
            type: string
            format: date-time

    # --- Template Messages ---

    TemplateCreatedEvent:
      name: TemplateCreatedEvent
      title: Template Created
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          template_id:
            type: string
            format: uuid
          tenant_id:
            type: string
            format: uuid
            nullable: true
          name:
            type: string
          description:
            type: string
            nullable: true
          category:
            type: string
          tier:
            type: string
          price:
            type: number
          creator_id:
            type: string
            format: uuid
          is_public:
            type: boolean
          is_platform_template:
            type: boolean
          created_by:
            type: string
            format: uuid
          created_at:
            type: string
            format: date-time

    TemplateUpdatedEvent:
      name: TemplateUpdatedEvent
      title: Template Updated
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          template_id:
            type: string
            format: uuid
          tenant_id:
            type: string
            format: uuid
            nullable: true
          name:
            type: string
          description:
            type: string
            nullable: true
          category:
            type: string
          tier:
            type: string
          price:
            type: number
          is_public:
            type: boolean
          is_approved:
            type: boolean
          updated_by:
            type: string
            format: uuid
          updated_at:
            type: string
            format: date-time

    TemplatePurchasedEvent:
      name: TemplatePurchasedEvent
      title: Template Purchased
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          purchase_id:
            type: string
            format: uuid
          template_id:
            type: string
            format: uuid
          template_name:
            type: string
          buyer_tenant_id:
            type: string
            format: uuid
          buyer_user_id:
            type: string
            format: uuid
          creator_tenant_id:
            type: string
            format: uuid
          creator_user_id:
            type: string
            format: uuid
          price_paid:
            type: number
          transaction_id:
            type: string
          eventzr_commission:
            type: number
          creator_payout:
            type: number
          purchased_at:
            type: string
            format: date-time

    # --- Theme Messages ---

    ThemeCreatedEvent:
      name: ThemeCreatedEvent
      title: Theme Created
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          theme_id:
            type: string
            format: uuid
          tenant_id:
            type: string
            format: uuid
            nullable: true
          name:
            type: string
          description:
            type: string
            nullable: true
          is_public:
            type: boolean
          is_platform_theme:
            type: boolean
          design_tokens:
            type: object
            properties:
              colors:
                type: object
                properties:
                  primary: { type: string }
                  secondary: { type: string }
                  accent: { type: string }
                  background: { type: string }
                  text: { type: string }
              typography:
                type: object
                properties:
                  font_family_heading: { type: string }
                  font_family_body: { type: string }
          created_by:
            type: string
            format: uuid
          created_at:
            type: string
            format: date-time

    ThemeUpdatedEvent:
      name: ThemeUpdatedEvent
      title: Theme Updated
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          theme_id:
            type: string
            format: uuid
          tenant_id:
            type: string
            format: uuid
            nullable: true
          name:
            type: string
          description:
            type: string
            nullable: true
          is_public:
            type: boolean
          updated_by:
            type: string
            format: uuid
          updated_at:
            type: string
            format: date-time

    ThemeAppliedEvent:
      name: ThemeAppliedEvent
      title: Theme Applied
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          page_id:
            type: string
            format: uuid
          tenant_id:
            type: string
            format: uuid
          theme_id:
            type: string
            format: uuid
          theme_name:
            type: string
          previous_theme_id:
            type: string
            format: uuid
            nullable: true
          applied_by:
            type: string
            format: uuid
          applied_at:
            type: string
            format: date-time

    # --- Domain Messages ---

    DomainRegisteredEvent:
      name: DomainRegisteredEvent
      title: Domain Registered
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          page_id:
            type: string
            format: uuid
          tenant_id:
            type: string
            format: uuid
          domain:
            type: string
          domain_status:
            type: string
            enum: [pending, verifying, verified, active, failed, expired]
          registered_by:
            type: string
            format: uuid
          registered_at:
            type: string
            format: date-time

    DomainVerifiedEvent:
      name: DomainVerifiedEvent
      title: Domain Verified
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          page_id:
            type: string
            format: uuid
          tenant_id:
            type: string
            format: uuid
          domain:
            type: string
          domain_status:
            type: string
          verification_method:
            type: string
            enum: [dns, http, txt_record]
          verified_at:
            type: string
            format: date-time

    DomainFailedEvent:
      name: DomainFailedEvent
      title: Domain Failed
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          page_id:
            type: string
            format: uuid
          tenant_id:
            type: string
            format: uuid
          domain:
            type: string
          domain_status:
            type: string
          error_code:
            type: string
          error_message:
            type: string
          failed_at:
            type: string
            format: date-time

    # --- A/B Test Messages ---

    ABTestStartedEvent:
      name: ABTestStartedEvent
      title: A/B Test Started
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          test_id:
            type: string
            format: uuid
          tenant_id:
            type: string
            format: uuid
          page_id:
            type: string
            format: uuid
          name:
            type: string
          variant_count:
            type: integer
          started_by:
            type: string
            format: uuid
          started_at:
            type: string
            format: date-time

    ABTestCompletedEvent:
      name: ABTestCompletedEvent
      title: A/B Test Completed
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          test_id:
            type: string
            format: uuid
          tenant_id:
            type: string
            format: uuid
          page_id:
            type: string
            format: uuid
          name:
            type: string
          winner_variant_id:
            type: string
            format: uuid
            nullable: true
          confidence_level:
            type: number
            nullable: true
          total_views:
            type: integer
          total_conversions:
            type: integer
          completed_by:
            type: string
            format: uuid
          completed_at:
            type: string
            format: date-time

    # --- Comment Messages ---

    CommentCreatedEvent:
      name: CommentCreatedEvent
      title: Comment Created
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          comment_id:
            type: string
            format: uuid
          page_id:
            type: string
            format: uuid
          section_id:
            type: string
            format: uuid
            nullable: true
          author_id:
            type: string
            format: uuid
          text:
            type: string
          position:
            type: object
            description: Position coordinates for inline comments
            nullable: true
          parent_comment_id:
            type: string
            format: uuid
            nullable: true
            description: Parent comment ID for threaded replies
          mentions:
            type: array
            items:
              type: string
              format: uuid
            description: List of mentioned user IDs
          created_at:
            type: string
            format: date-time

    CommentUpdatedEvent:
      name: CommentUpdatedEvent
      title: Comment Updated
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          comment_id:
            type: string
            format: uuid
          page_id:
            type: string
            format: uuid
          text:
            type: string
          position:
            type: object
            nullable: true
          updated_by:
            type: string
            format: uuid
          updated_at:
            type: string
            format: date-time

    CommentDeletedEvent:
      name: CommentDeletedEvent
      title: Comment Deleted
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          comment_id:
            type: string
            format: uuid
          page_id:
            type: string
            format: uuid
          deleted_by:
            type: string
            format: uuid
          deleted_at:
            type: string
            format: date-time

    CommentResolvedEvent:
      name: CommentResolvedEvent
      title: Comment Resolved
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          comment_id:
            type: string
            format: uuid
          page_id:
            type: string
            format: uuid
          resolved_by:
            type: string
            format: uuid
          resolved_at:
            type: string
            format: date-time

    CommentMentionedEvent:
      name: CommentMentionedEvent
      title: Comment Mention
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          comment_id:
            type: string
            format: uuid
          page_id:
            type: string
            format: uuid
          author_id:
            type: string
            format: uuid
          mentioned_user_id:
            type: string
            format: uuid
          text:
            type: string
          created_at:
            type: string
            format: date-time

    # --- Profile Template Messages ---

    ProfileTemplateAppliedEvent:
      name: ProfileTemplateAppliedEvent
      title: Profile Template Applied
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          preference_id:
            type: string
            format: uuid
          page_id:
            type: string
            format: uuid
          template_key:
            type: string
            description: Profile template key (e.g. artist, speaker, dj)
          entity_type:
            type: string
          entity_id:
            type: string
            format: uuid
          enabled_sections:
            type: array
            items:
              type: string
            description: List of enabled section keys
          section_order:
            type: array
            items:
              type: string
            description: Ordered list of section keys
          custom_theme_id:
            type: string
            format: uuid
            nullable: true
          created_by:
            type: string
            format: uuid
          created_at:
            type: string
            format: date-time

    ProfileTemplateCustomizedEvent:
      name: ProfileTemplateCustomizedEvent
      title: Profile Template Customized
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          preference_id:
            type: string
            format: uuid
          page_id:
            type: string
            format: uuid
          section_key:
            type: string
            description: The section that was customized
          customizations:
            type: object
            description: Key-value pairs of customization overrides
          customized_by:
            type: string
            format: uuid
          customized_at:
            type: string
            format: date-time

    ProfileTemplatePreferenceUpdatedEvent:
      name: ProfileTemplatePreferenceUpdatedEvent
      title: Profile Template Preference Updated
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          preference_id:
            type: string
            format: uuid
          page_id:
            type: string
            format: uuid
          template_key:
            type: string
          enabled_sections:
            type: array
            items:
              type: string
          section_order:
            type: array
            items:
              type: string
          custom_theme_id:
            type: string
            format: uuid
            nullable: true
          updated_by:
            type: string
            format: uuid
          updated_at:
            type: string
            format: date-time

    ProfileTemplateRemovedEvent:
      name: ProfileTemplateRemovedEvent
      title: Profile Template Removed
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          preference_id:
            type: string
            format: uuid
          page_id:
            type: string
            format: uuid
          template_key:
            type: string
          removed_by:
            type: string
            format: uuid
          removed_at:
            type: string
            format: date-time

    # --- Template Query Messages (Request/Response) ---

    TemplateQueryRequestedEvent:
      name: TemplateQueryRequestedEvent
      title: Template Query Requested
      contentType: application/cloudevents+json
      description: |
        Consumed by webify-svc via NestJS EventEmitter. Triggers a template lookup
        and responds with a TemplateQueryResponseEvent keyed by correlation ID.
      payload:
        type: object
        properties:
          tenantId:
            type: string
            format: uuid
          category:
            type: string
          isPublic:
            type: boolean
          limit:
            type: integer
          filters:
            type: object
            nullable: true
            properties:
              tags:
                type: array
                items:
                  type: string
              minRating:
                type: number
              subcategoryId:
                type: string

    TemplateQueryResponseEvent:
      name: TemplateQueryResponseEvent
      title: Template Query Response
      contentType: application/cloudevents+json
      description: |
        Emitted by webify-svc in response to a template.query.requested event.
        Keyed by correlation ID so the requester can match responses to requests.
      payload:
        type: object
        properties:
          templates:
            type: array
            items:
              type: object
            description: Array of matching template objects
          totalCount:
            type: integer
          retrievedAt:
            type: string
            format: date-time

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

    # --- Wallet Messages (from wallet-svc) ---

    CreditDeductedEvent:
      name: CreditDeductedEvent
      title: Credit Deducted
      contentType: application/cloudevents+json
      description: Emitted by wallet-svc when AI credits are deducted.
      payload:
        type: object
        properties:
          transaction_id:
            type: string
          tenant_id:
            type: string
            format: uuid
          user_id:
            type: string
            format: uuid
          amount:
            type: number
          reason:
            type: string
          operation:
            type: string
            nullable: true
            description: The operation that triggered the deduction (e.g. ai-page-generation)

    CreditRefundedEvent:
      name: CreditRefundedEvent
      title: Credit Refunded
      contentType: application/cloudevents+json
      description: Emitted by wallet-svc when AI credits are refunded.
      payload:
        type: object
        properties:
          transaction_id:
            type: string
          tenant_id:
            type: string
            format: uuid
          user_id:
            type: string
            format: uuid
          amount:
            type: number
          reason:
            type: string
          original_transaction_id:
            type: string
            description: The original transaction that is being refunded

    # --- Domain Messages (from domains-svc) ---

    SSLIssuedEvent:
      name: SSLIssuedEvent
      title: SSL Certificate Issued
      contentType: application/cloudevents+json
      description: Emitted by domains-svc when a new SSL certificate is issued.
      payload:
        type: object
        properties:
          domain_id:
            type: string
            format: uuid
          domain:
            type: string
          tenant_id:
            type: string
            format: uuid
          ssl_expires_at:
            type: string
            format: date-time

    SSLExpiringEvent:
      name: SSLExpiringEvent
      title: SSL Certificate Expiring
      contentType: application/cloudevents+json
      description: Emitted by domains-svc when an SSL certificate is approaching expiry.
      payload:
        type: object
        properties:
          domain_id:
            type: string
            format: uuid
          domain:
            type: string
          tenant_id:
            type: string
            format: uuid
          expires_at:
            type: string
            format: date-time
          days_until_expiry:
            type: integer

    # --- CMS Messages (from cms-svc) ---

    ContentUpdatedEvent:
      name: ContentUpdatedEvent
      title: CMS Content Updated
      contentType: application/cloudevents+json
      description: Emitted by cms-svc when content is updated.
      payload:
        type: object
        properties:
          content_id:
            type: string
            format: uuid
          tenant_id:
            type: string
            format: uuid
          content_type:
            type: string
          updated_fields:
            type: array
            items:
              type: string

    MediaUploadedEvent:
      name: MediaUploadedEvent
      title: CMS Media Uploaded
      contentType: application/cloudevents+json
      description: Emitted by cms-svc when new media is uploaded.
      payload:
        type: object
        properties:
          media_id:
            type: string
            format: uuid
          tenant_id:
            type: string
            format: uuid
          media_type:
            type: string
          url:
            type: string
            format: uri
          metadata:
            type: object
            nullable: true

    # --- Taxonomy Messages (from taxonomy-svc) ---

    CategoryUpdatedEvent:
      name: CategoryUpdatedEvent
      title: Taxonomy Category Updated
      contentType: application/cloudevents+json
      description: Emitted by taxonomy-svc when a category is updated.
      payload:
        type: object
        properties:
          category_id:
            type: string
            format: uuid
          category_key:
            type: string
          name:
            type: string
          parent_id:
            type: string
            format: uuid
            nullable: true
          metadata:
            type: object
            nullable: true
