import type { FormSchema } from '../../../forms/types'

/**
 * Execution interface configuration
 * Defines how a resource is executed via the UI (forms, scheduling, webhooks)
 * Applies to both agents and workflows
 */
export interface ExecutionInterface {
  /** Form configuration for execution inputs */
  form: ExecutionFormSchema

  /** Optional: Schedule configuration */
  schedule?: ScheduleConfig

  /** Optional: Webhook trigger configuration */
  webhook?: WebhookConfig
}

/**
 * Execution form schema
 * Extends FormSchema with execution-specific fields
 */
export interface ExecutionFormSchema extends FormSchema {
  /**
   * Field mappings to resource input schema
   * Maps form field names to contract input paths
   * If omitted, field names must match contract input keys exactly
   */
  fieldMappings?: Record<string, string>

  /**
   * Submit button configuration
   * Default: { label: 'Run', loadingLabel: 'Running...' }
   */
  submitButton?: {
    label?: string
    loadingLabel?: string
    confirmMessage?: string  // Optional confirmation dialog
  }
}

/**
 * Schedule configuration for automated execution
 */
export interface ScheduleConfig {
  /** Whether scheduling is enabled for this resource */
  enabled: boolean
  /** Default schedule (cron expression) */
  defaultSchedule?: string
  /** Allowed schedule patterns (if restricted) */
  allowedPatterns?: string[]
}

/**
 * Webhook configuration for external triggers
 */
export interface WebhookConfig {
  /** Whether webhook trigger is enabled */
  enabled: boolean
  /** Expected payload schema (for documentation) */
  payloadSchema?: unknown
}
