export type CodeToolConfigureHooks = {
  getCodeWorkDir: () => string
  getCodeMdExcludes?: () => string[]
}

let hooks: CodeToolConfigureHooks | null = null

export function configure(next: CodeToolConfigureHooks | null): void {
  hooks = next
}

export function resetConfigure(): void {
  hooks = null
}

export function getCachedConfigure(): CodeToolConfigureHooks | null {
  return hooks
}

export function requireCodeWorkDir(): string {
  if (!hooks?.getCodeWorkDir) {
    throw new Error('CodeTool: code work directory not configured')
  }
  const dir = hooks.getCodeWorkDir()
  if (!dir || !dir.trim()) {
    throw new Error('CodeTool: code work directory not configured')
  }
  return dir
}

export function getCodeMdExcludes(): string[] {
  return hooks?.getCodeMdExcludes?.() ?? []
}
