/**
 * Types for the Project Knowledge Base.
 * Structured project understanding that persists across sessions.
 */

/** Dependency graph: file → its imports */
export interface ArchitectureGraph {
  version: 1
  /** Map of file path → list of imported file paths (resolved relative) */
  dependencies: Record<string, string[]>
  /** Files that nothing imports (likely entry points) */
  entryPoints: string[]
  /** Directory → list of files (module grouping) */
  modules: Record<string, string[]>
  /** When this was last built */
  builtAt: number
  /** Root directory scanned */
  rootDir: string
}

/** Detected coding patterns in the project */
export interface PatternProfile {
  version: 1
  /** Detected test framework (jest, vitest, mocha, playwright, etc.) */
  testFramework: string | null
  /** Detected state management (zustand, redux, jotai, etc.) */
  stateManagement: string | null
  /** Naming convention: camelCase, snake_case, etc. */
  namingConvention: string
  /** Error handling style: try-catch, Result type, etc. */
  errorHandlingStyle: string
  /** File organization: by-feature, by-type, flat */
  fileOrganization: string
  /** Detected package manager: npm, yarn, pnpm, bun */
  packageManager: string | null
  /** Primary language: typescript, javascript, python, etc. */
  primaryLanguage: string
  /** Framework: react, next, vue, express, etc. */
  framework: string | null
  /** When this was last analyzed */
  analyzedAt: number
}

/** Files ranked by change frequency and import fan-in */
export interface HotspotMap {
  version: 1
  /** Files ranked by git change frequency (most changed first) */
  byChangeFrequency: Array<{ path: string; changes: number }>
  /** Files ranked by import fan-in (most imported first) */
  byImportFanIn: Array<{ path: string; importers: number }>
  /** Files with corresponding test files */
  testedFiles: Array<{ source: string; test: string }>
  /** When this was last computed */
  computedAt: number
}

/** Full knowledge base state */
export interface ProjectKnowledge {
  architecture: ArchitectureGraph | null
  patterns: PatternProfile | null
  hotspots: HotspotMap | null
}
