asyncapi: '2.6.0'
info:
  title: chat-svc Async API
  version: '1.0.0'
  description: Kafka event topics produced and consumed by chat-svc
  contact:
    name: EventZR Team

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

channels:
  eventzr.chat.message.sent.v1:
    publish:
      summary: Message sent event
      operationId: publishMessageSent
      message:
        $ref: '#/components/messages/MessageSentEvent'

  eventzr.chat.thread.created.v1:
    publish:
      summary: Thread created event (via outbox)
      operationId: publishThreadCreated
      message:
        $ref: '#/components/messages/ThreadCreatedEvent'

  eventzr.chat.thread.updated.v1:
    publish:
      summary: Thread updated event (via outbox)
      operationId: publishThreadUpdated
      message:
        $ref: '#/components/messages/ThreadUpdatedEvent'

  eventzr.chat.thread.archived.v1:
    publish:
      summary: Thread archived event (via outbox)
      operationId: publishThreadArchived
      message:
        $ref: '#/components/messages/ThreadArchivedEvent'

  user-events:
    subscribe:
      summary: User lifecycle events consumed by chat-svc
      operationId: consumeUserEvents
      message:
        oneOf:
          - $ref: '#/components/messages/UserProfileUpdatedEvent'
          - $ref: '#/components/messages/UserDeletedEvent'

components:
  messages:
    MessageSentEvent:
      name: MessageSentEvent
      title: Message Sent
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          specversion: { type: string, const: '1.0' }
          type: { type: string, const: 'eventzr.chat.message.sent.v1' }
          source: { type: string, const: 'chat-svc' }
          id: { type: string, format: uuid }
          time: { type: string, format: date-time }
          subject: { type: string, description: 'messageId' }
          datacontenttype: { type: string, const: 'application/json' }
          data:
            type: object
            properties:
              messageId: { type: string, format: uuid }
              threadId: { type: string, format: uuid }
              tenantId: { type: string, format: uuid }
              senderId: { type: string, format: uuid }
              content: { type: string }
              attachments: { type: array }
              mentions: { type: array }
              parentMessageId: { type: string, format: uuid, nullable: true }
              sentAt: { type: string, format: date-time }

    ThreadCreatedEvent:
      name: ThreadCreatedEvent
      title: Thread Created
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          specversion: { type: string, const: '1.0' }
          type: { type: string, const: 'eventzr.chat.thread.created.v1' }
          source: { type: string, const: 'chat-svc' }
          data:
            type: object
            properties:
              threadId: { type: string, format: uuid }
              threadType: { type: string, enum: [direct, group, channel] }
              threadName: { type: string, nullable: true }
              createdById: { type: string, format: uuid }
              participantIds: { type: array, items: { type: string, format: uuid } }
              createdAt: { type: string, format: date-time }

    ThreadUpdatedEvent:
      name: ThreadUpdatedEvent
      title: Thread Updated
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          type: { type: string, const: 'eventzr.chat.thread.updated.v1' }
          data:
            type: object
            properties:
              threadId: { type: string, format: uuid }
              updatedFields: { type: array, items: { type: string } }
              updatedById: { type: string, format: uuid }
              updatedAt: { type: string, format: date-time }

    ThreadArchivedEvent:
      name: ThreadArchivedEvent
      title: Thread Archived
      contentType: application/cloudevents+json
      payload:
        type: object
        properties:
          type: { type: string, const: 'eventzr.chat.thread.archived.v1' }
          data:
            type: object
            properties:
              threadId: { type: string, format: uuid }
              archivedById: { type: string, format: uuid }
              archivedAt: { type: string, format: date-time }

    UserProfileUpdatedEvent:
      name: UserProfileUpdatedEvent
      title: User Profile Updated (consumed)
      payload:
        type: object
        properties:
          type: { type: string, const: 'eventzr.users.profile.updated.v1' }
          data:
            type: object
            properties:
              userId: { type: string, format: uuid }

    UserDeletedEvent:
      name: UserDeletedEvent
      title: User Deleted (consumed - GDPR)
      payload:
        type: object
        properties:
          type: { type: string, const: 'eventzr.users.deleted.v1' }
          data:
            type: object
            properties:
              userId: { type: string, format: uuid }
