/**
 * Integration type definitions
 */

export interface IntegrationCredentialField {
  type: 'text' | 'password';
  label: string;
  description: string;
  required: boolean;
}

/**
 * A single connection (account) for an integration.
 * Users can have multiple connections per integration type.
 */
export interface IntegrationConnection {
  /** Unique connection ID */
  id: string;
  /** User-defined label (e.g., "Main Account", "Support Team") */
  label: string;
  /** Masked credentials for display (e.g., "****abc123") */
  credentials?: Record<string, string> | null;
  /** API version used by this connection (e.g., "v1", "v2") */
  api_version: string;
  /** When this connection was created */
  created_at: string;
  /** When this connection was last updated */
  updated_at: string;
}

export interface Integration {
  slug: string;
  name: string;
  description: string;
  category: string;
  icon?: string;
  website?: string;
  docs_url?: string;
  /** True if at least one connection exists */
  connected: boolean;
  enabled: boolean;
  credentials?: Record<string, IntegrationCredentialField>;
  /** All connections for this integration */
  connections?: IntegrationConnection[];
}

export interface IntegrationStatus {
  integration: Integration;
}

/**
 * Response from creating a new connection
 */
export interface CreateConnectionResponse {
  success: boolean;
  connection_id: string;
  message: string;
}

/**
 * Response from updating a connection
 */
export interface UpdateConnectionResponse {
  success: boolean;
  message: string;
}

/**
 * Response from deleting a connection
 */
export interface DeleteConnectionResponse {
  success: boolean;
  message: string;
  /** Number of workflows that were paused (when deleting last connection) */
  paused_workflows?: number;
}

/**
 * Workflow affected by disconnecting an integration
 */
export interface AffectedWorkflow {
  id: number;
  name: string;
}
