/**
 * Shared Apify param/result types (browser-safe)
 *
 * These types define the public interface for Apify operations -- used by both
 * the server-side adapter and the SDK typed wrappers. They contain zero Node.js
 * dependencies and are safe to import in any environment.
 *
 * Server-internal types (credentials, retry logic) remain in
 * server/adapters/apify/fetch/run-actor/index.ts
 */

// ============================================================================
// Run Actor
// ============================================================================

/**
 * Run actor parameters
 */
export interface RunActorParams {
  actorId: string
  input?: Record<string, unknown>
  timeoutSecs?: number
  pollIntervalSecs?: number
  maxItems?: number
}

/**
 * Run actor result
 */
export interface RunActorResult {
  status: 'SUCCEEDED' | 'FAILED' | 'ABORTED' | 'TIMED_OUT'
  runId: string
  datasetId: string
  items: unknown[]
  totalCount: number
  executionTimeMs: number
}

// ============================================================================
// Get Dataset Items
// ============================================================================

/**
 * Get dataset items parameters
 */
export interface GetDatasetItemsParams {
  datasetId: string
  maxItems?: number
  offset?: number
}

/**
 * Get dataset items result
 */
export interface GetDatasetItemsResult {
  items: unknown[]
  totalCount: number
}

// ============================================================================
// Start Actor (async, fire-and-forget)
// ============================================================================

/**
 * Webhook configuration for actor run notifications
 */
export interface ApifyWebhookConfig {
  eventTypes: string[] // e.g. ['ACTOR.RUN.SUCCEEDED', 'ACTOR.RUN.FAILED']
  requestUrl: string // URL to POST when event fires
  payloadTemplate?: string
  headersTemplate?: string
}

/**
 * Start actor parameters (async, no polling)
 */
export interface StartActorParams {
  actorId: string
  input?: Record<string, unknown>
  webhooks?: ApifyWebhookConfig[]
  timeoutSecs?: number
  maxItems?: number
}

/**
 * Start actor result (immediate, no waiting)
 */
export interface StartActorResult {
  status: 'STARTED'
  runId: string
  datasetId: string
}
