/**
 * Types for Symbol Search functionality
 * Used by both Main Process and IPC communication
 */

// Symbol types that can be detected
export type SymbolType =
  | 'function'
  | 'method'
  | 'class'
  | 'struct'
  | 'interface'
  | 'type'
  | 'constant'
  | 'variable'
  | 'enum'
  | 'property'
  | 'module'
  | 'namespace'
  | 'heading'
  // Terraform-specific types
  | 'resource'
  | 'data'
  | 'output'
  | 'provider';

// A single symbol search result
export interface SymbolResult {
  name: string;
  type: SymbolType;
  filePath: string;
  relativePath: string;
  lineNumber: number;
  lineContent: string;
  language: string;
  nameLower?: string; // Pre-computed lowercase name for efficient filtering
  mtimeMs?: number; // File modification time in milliseconds for scoring
}

// Response from symbol search command
export interface SymbolSearchResponse {
  success: boolean;
  directory?: string;
  language?: string;
  symbols: SymbolResult[];
  symbolCount: number;
  unfilteredCount?: number; // Number of symbols before relativePath filtering
  searchMode: 'full' | 'cached';
  partial: boolean;
  maxSymbols: number;
  error?: string;
}

// Response from check-rg command
export interface RgCheckResponse {
  rgAvailable: boolean;
  rgPath: string | null;
}

// Language info for list-languages command
export interface LanguageInfo {
  key: string;
  extension: string;
  displayName: string;
}

// Response from list-languages command
export interface LanguagesResponse {
  languages: LanguageInfo[];
}

// Symbol search options
export interface SymbolSearchOptions {
  maxSymbols?: number;
  timeout?: number;
  rgPath?: string | null;
  excludePatterns?: string[];
  includePatterns?: string[];
  followSymlinks?: boolean;
}

// Symbol cache metadata for a language
export interface LanguageCacheMetadata {
  symbolCount: number;
  searchMode: 'full' | 'quick';
  // Hash of search-affecting settings at save time. When current settings
  // produce a different hash, the cache is treated as stale even if within
  // TTL so setting changes (e.g. includePatterns, followSymlinks) take
  // effect on the next search.
  settingsHash?: string;
}

// Symbol cache metadata
export interface SymbolCacheMetadata {
  version: string;
  directory: string;
  createdAt: string;
  updatedAt: string;
  languages: Record<string, LanguageCacheMetadata>;
  totalSymbolCount: number;
  ttlSeconds: number;
}
