/**
 * Shared TypeScript types for the copilot plugin.
 */

import type { Ctx } from '@milkdown/kit/core'
import type { EditorView } from '@milkdown/prose/view'
import type { Transaction } from '@milkdown/prose/model'

/** State tracked by the copilot plugin key */
export interface CopilotState {
  from: number
  to: number
  suggestion: string
}

/** Runtime state associated with each editor view */
export interface CopilotRuntime {
  enabled: boolean
  debounceTimer: ReturnType<typeof setTimeout> | null
  abortController: AbortController | null
  ctx: Ctx
  requestSeq: number
  docVersion: number
}

/** Configuration for the copilot plugin */
export interface CopilotConfig {
  fetchSuggestion: (prefix: string, suffix: string, languageId: string, signal?: AbortSignal) => Promise<string>
  debounceMs?: number
}

/** Result of checking document size limits */
export interface SizeCheckResult {
  size: number
  overLimit: boolean
}

/** Mark type from milkdown schema */
export interface GhostMarkType {
  create(): any
}

/** Helper type for transaction operations */
export type TransactionLike = {
  mapping: { map(pos: number, bias: number): number; mapResult(pos: number, bias: number): { pos: number } }
  doc: { content: { size: number }; resolve(pos: number): any; textBetween(from: number, to: number, blockSeparator string, leafText string): string }
  tr: any
}
