/**
 * Webhook Endpoint Domain Types
 *
 * Browser-safe domain types for generic inbound webhook endpoints.
 * These are camelCase representations of the `webhook_endpoints` DB table.
 *
 * Transform from snake_case DB rows happens in the API service layer,
 * not here (per core-package.md conventions).
 */

/**
 * Lifecycle status of a webhook endpoint.
 * - `active`: Endpoint accepts inbound requests and triggers the target workflow
 * - `paused`: Endpoint exists but rejects inbound requests with 404
 */
export type WebhookEndpointStatus = 'active' | 'paused'

/**
 * Generic inbound webhook endpoint domain type.
 *
 * Each endpoint gets a unique opaque URL (`/api/webhooks/inbound/:key`)
 * that maps to a target workflow resource within an organization.
 */
export interface WebhookEndpoint {
  /** UUID primary key */
  id: string
  /** Organization this endpoint belongs to */
  organizationId: string
  /**
   * Unique opaque key used in the inbound URL.
   * Format: `wh_` + 32 crypto-random hex chars (128 bits of entropy).
   * This key IS the credential — it must be kept secret.
   * Set ONLY on the return value of `create()` — undefined on list/get/getEndpointByKey responses.
   */
  key?: string
  /**
   * First 8 characters of the plaintext key for display and grep hints.
   * Safe to show in list views — not sufficient to reconstruct the full key.
   * Null on legacy rows that predate the key_hash migration.
   */
  keyPrefix: string | null
  /** User-facing label (e.g., "Zapier → Lead Intake") */
  name: string
  /** Optional description for the endpoint */
  description: string | null
  /** Target workflow resourceId to invoke on inbound request, or null if not yet assigned */
  resourceId: string | null
  /** Whether the endpoint is accepting requests */
  status: WebhookEndpointStatus
  /** Timestamp of the most recent successful inbound request, or null */
  lastTriggeredAt: string | null
  /** Running total of inbound requests received */
  requestCount: number
  /** ISO 8601 creation timestamp */
  createdAt: string
  /** ISO 8601 last-updated timestamp */
  updatedAt: string
}
