export interface FeatureFlags {
  readonly importExport: boolean;
  readonly resources: boolean;
  readonly prompts: boolean;
  readonly vectorSearch: boolean;
}

export interface MemoryNodeConfig {
  readonly serverName: string;
  readonly serverVersion: string;
  readonly dbPath: string;
  readonly maxEntryBytes: number;
  readonly maxSearchResults: number;
  readonly auditLogEnabled: boolean;
  readonly inputLimits: {
    readonly maxTags: number;
    readonly maxTitleChars: number;
    readonly maxSummaryChars: number;
    readonly maxSourceRefChars: number;
    readonly maxSourceUriChars: number;
    readonly maxProjectIdChars: number;
    readonly maxScopeChars: number;
    readonly maxTopicChars: number;
    readonly maxTagChars: number;
  };
  readonly featureFlags: FeatureFlags;
}

export interface MemoryNodeContext {
  readonly config: MemoryNodeConfig;
  readonly db: DatabaseAdapter;
}

export interface ProjectResolution {
  readonly projectId: string;
  readonly canonicalPath?: string;
  readonly warnings: string[];
}

export interface ToolBaseResult {
  readonly ok: true;
  readonly project_id: string;
  readonly warnings: string[];
}

export interface ToolErrorResult {
  readonly ok: false;
  readonly error_code: string;
  readonly detail: string;
  readonly project_id?: string;
}

export interface DatabaseRow {
  [key: string]: unknown;
}

export interface DatabaseAdapter {
  run(sql: string, params?: readonly unknown[]): Promise<{ lastID: number; changes: number }>;
  get<T>(sql: string, params?: readonly unknown[]): Promise<T | undefined>;
  all<T>(sql: string, params?: readonly unknown[]): Promise<T[]>;
  exec(sql: string): Promise<void>;
  close(): Promise<void>;
}

export interface AddEntryInput {
  project_path: string;
  project_id?: string;
  scope: string;
  topic: string;
  title?: string;
  content: string;
  summary?: string;
  source_type: string;
  source_ref?: string;
  source_path?: string;
  source_uri?: string;
  importance?: number;
  confidence?: number;
  tags?: string[];
  dedupe?: boolean;
}

export interface SearchInput {
  project_path?: string;
  project_id?: string;
  query: string;
  mode?: "project" | "cross_project";
  scope?: string;
  topic?: string;
  source_type?: string;
  status?: string;
  limit?: number;
  include_content?: boolean;
  tags?: string[];
}

export interface ReadEntryInput {
  project_path?: string;
  project_id?: string;
  entry_id: string;
  mode?: "project" | "cross_project";
}

export interface ListTaxonomyInput {
  project_path?: string;
  project_id?: string;
  status?: string;
  scope?: string;
  topic?: string;
}

export interface InvalidateEntryInput {
  project_path?: string;
  project_id?: string;
  entry_id: string;
  reason?: string;
}
