/**
 * SDK Flow Visualization - Step-Definitionen mit Datenfluss
 * Barrel re-export — implementation split into sdk-flow/ subdirectory files
 */

export type { SDKFlowStep } from './types'
export { FLOW_PACKAGES } from './types'

export { STEPS_VORBEREITUNG } from './steps-vorbereitung'
export { STEPS_ANALYSE } from './steps-analyse'
export { STEPS_DOKUMENTATION, STEPS_RECHTLICHE_TEXTE } from './steps-dokumentation'
export { STEPS_BETRIEB } from './steps-betrieb'

import { STEPS_VORBEREITUNG } from './steps-vorbereitung'
import { STEPS_ANALYSE } from './steps-analyse'
import { STEPS_DOKUMENTATION, STEPS_RECHTLICHE_TEXTE } from './steps-dokumentation'
import { STEPS_BETRIEB } from './steps-betrieb'
import type { SDKFlowStep } from './types'

export const SDK_FLOW_STEPS: SDKFlowStep[] = [
  ...STEPS_VORBEREITUNG,
  ...STEPS_ANALYSE,
  ...STEPS_DOKUMENTATION,
  ...STEPS_RECHTLICHE_TEXTE,
  ...STEPS_BETRIEB,
]

// =============================================================================
// HELPER FUNCTIONS
// =============================================================================

/** Find which step produces a given SDKState property */
export function findProducerStep(property: string): SDKFlowStep | undefined {
  return SDK_FLOW_STEPS.find(s => s.outputs.includes(property))
}

/** Get all unique DB tables used across all steps */
export function getAllDbTables(): string[] {
  const tables = new Set<string>()
  SDK_FLOW_STEPS.forEach(s => s.dbTables.forEach(t => tables.add(t)))
  return Array.from(tables)
}

/** Get all unique RAG collections used across all steps */
export function getAllRagCollections(): string[] {
  const collections = new Set<string>()
  SDK_FLOW_STEPS.forEach(s => s.ragCollections.forEach(c => collections.add(c)))
  return Array.from(collections)
}

/** Get steps that use a specific DB table */
export function getStepsUsingTable(table: string): SDKFlowStep[] {
  return SDK_FLOW_STEPS.filter(s => s.dbTables.includes(table))
}

/** Get steps that use a specific RAG collection */
export function getStepsUsingRag(collection: string): SDKFlowStep[] {
  return SDK_FLOW_STEPS.filter(s => s.ragCollections.includes(collection))
}
