/**
 * Core type definitions — ported from MCP-SuperAssistant render_prescript
 */

/** Configuration for the function call renderer */
export interface FunctionCallRendererConfig {
  knownLanguages: string[]
  handleLanguageTags: boolean
  maxLinesAfterLangTag: number
  targetSelectors: string[]
  enableDirectMonitoring: boolean
  streamingContainerSelectors: string[]
  function_result_selector?: string[]
  updateThrottle: number
  streamingMonitoringInterval: number
  largeContentThreshold: number
  progressiveUpdateInterval: number
  maxContentPreviewLength: number
  usePositionFixed: boolean
  stabilizeTimeout: number
  debug: boolean
  useHostTheme: boolean
  enableStalledStreamDetection: boolean
  stalledStreamTimeout: number
  stalledStreamCheckInterval: number
  useCodeMirrorExtraction: boolean
}

/** Parameter data extracted from function calls */
export interface Parameter {
  name: string
  value: string
  isComplete: boolean
  isNew?: boolean
  isStreaming?: boolean
  originalContent?: string
  isLargeContent?: boolean
  contentLength?: number
  truncated?: boolean
  isIncompleteTag?: boolean
}

/** Information about a function call detection */
export interface FunctionInfo {
  hasFunctionCalls: boolean
  isComplete: boolean
  hasInvoke: boolean
  hasParameters: boolean
  hasClosingTags: boolean
  languageTag: string | null
  detectedBlockType: string | null
  partialTagDetected: boolean
  invokeName?: string
  textContent?: string
  description?: string
}

/** Partial parameter state during streaming */
export interface PartialParameterState {
  [paramName: string]: string
}

/** Custom HTMLDivElement with auto-scroll properties */
export interface ParamValueElement extends HTMLDivElement {
  _autoScrollToBottom?: () => void
  _autoScrollObserver?: MutationObserver
  _scrollTimeout?: number | null
  _userHasScrolled?: boolean
  _scrollListener?: EventListener
}

/** Stabilized block info */
export interface StabilizedBlock {
  block: HTMLDivElement
  placeholder: HTMLDivElement
  originalStyles: Partial<CSSStyleDeclaration>
}

/** MCP Tool call result */
export interface ToolCallResult {
  success: boolean
  result?: any
  error?: string
  toolName: string
  args: Record<string, any>
  timestamp: number
  duration?: number
}

/** Adapter capabilities */
export type AdapterCapability =
  | "text-insertion"
  | "form-submission"
  | "file-attachment"
  | "dom-manipulation"
  | "screenshot"

/** Adapter plugin interface */
export interface AdapterPlugin {
  readonly name: string
  readonly version: string
  readonly hostnames: (string | RegExp)[]
  readonly capabilities: AdapterCapability[]

  initialize(): Promise<void>
  activate(): Promise<void>
  deactivate(): Promise<void>
  cleanup(): Promise<void>

  insertText(text: string, options?: { targetElement?: HTMLElement }): Promise<boolean>
  submitForm(options?: { formElement?: HTMLFormElement }): Promise<boolean>

  getStatus(): "active" | "inactive" | "error" | "initializing" | "disabled" | "pending"
  isSupported(): boolean | Promise<boolean>
}

/** Execution history entry */
export interface ExecutionEntry {
  functionName: string
  callId: string
  parameters: Record<string, any>
  contentSignature: string
  timestamp: number
  result?: any
  status: "pending" | "success" | "error"
}
