/**
 * Test: Instantly Reply Received Trigger Definition
 *
 * Tests for the Instantly webhook trigger definition.
 */

import { describe, it, expect } from 'vitest'
import {
  instantlyReplyReceivedTrigger,
  type InstantlyReplyWebhookPayload
} from '../instantly-reply-received'

describe('instantlyReplyReceivedTrigger', () => {
  describe('trigger definition structure', () => {
    it('has correct triggerType', () => {
      expect(instantlyReplyReceivedTrigger.triggerType).toBe('webhook')
    })

    it('has correct config provider', () => {
      expect(instantlyReplyReceivedTrigger.config).toBeDefined()
      expect((instantlyReplyReceivedTrigger.config as { provider: string }).provider).toBe('instantly')
    })

    it('has correct config event', () => {
      expect(instantlyReplyReceivedTrigger.config).toBeDefined()
      expect((instantlyReplyReceivedTrigger.config as { event: string }).event).toBe('reply_received')
    })

    it('has correct resourceId', () => {
      expect(instantlyReplyReceivedTrigger.resourceId).toBe('trigger-instantly-reply-received')
    })

    it('has correct type', () => {
      expect(instantlyReplyReceivedTrigger.type).toBe('trigger')
    })

    it('has required metadata fields', () => {
      expect(instantlyReplyReceivedTrigger.name).toBe('Instantly Reply Received')
      expect(instantlyReplyReceivedTrigger.description).toBeDefined()
      expect(instantlyReplyReceivedTrigger.version).toBe('1.0.0')
      expect(instantlyReplyReceivedTrigger.status).toBe('dev')
    })

    it('has webhookPath defined', () => {
      expect(instantlyReplyReceivedTrigger.webhookPath).toBe('/webhooks/instantly/reply-received')
    })
  })

  describe('type exports', () => {
    it('exports InstantlyReplyWebhookPayload type', () => {
      // Type assertion test - if this compiles, the type is exported
      const payload: InstantlyReplyWebhookPayload = {
        timestamp: '2025-01-15T10:30:00Z',
        event_type: 'reply_received',
        workspace: 'test',
        campaign_id: 'camp-1',
        lead_email: 'test@example.com',
        email_account: 'sender@example.com',
        unibox_url: 'https://instantly.ai/unibox/1',
        reply_to_uuid: 'uuid-1',
        reply_subject: 'Re: Test',
        reply_text: 'Test reply',
        reply_text_snippet: 'Test...',
        reply_html: '<p>Test reply</p>',
        step: 1,
        variant: 0,
        is_first: true
      }
      expect(payload.event_type).toBe('reply_received')
    })
  })
})
