/** The shape `tools/foundry/kitindex.py` writes to `public/kits.json`. */

export type Tier = 'S' | 'A' | 'B' | 'C' | 'D'
export type Family = 'drums' | 'hits' | 'bass' | 'tonal' | 'vox' | 'fx'

export type Sample = {
  n: number                 // the index SuperDirt will answer to: `# n <n>`
  name: string
  file: string
  url: string
  sr: number
  ch: number
  peak_dbfs: number
  rms_dbfs: number
  env: number[]
  // present only for kits the Foundry cut — a hand-made kit has none of this
  bars: number | null
  bpm: number | null
  dur_s: number | null
  tier: Tier | null
  grade: number | null
  family: Family | null
  stem_role: string | null
  track: string | null
  mode: 'loop' | 'chop' | null
  flags: string[]
  tags: Record<string, [string, number][]>
}

export type Kit = {
  kit: string
  n_samples: number
  source: 'foundry' | 'legacy'
  track: string | null
  family: Family | null
  bpm: number | null
  samples: Sample[]
}

export type KitIndex = {
  generated: string
  root: string
  peaks: number
  kits: Kit[]
}

/** Family → the role colour it shares with the orbit rail elsewhere on the bridge. */
export const FAMILY_COLOR: Record<string, string> = {
  drums: 'var(--color-percs)',
  hits: 'var(--color-blocked)',
  bass: 'var(--color-bass)',
  tonal: 'var(--color-melodic)',
  vox: 'var(--color-vox)',
  fx: 'var(--color-atmos)',
}
export const familyColor = (f?: string | null) =>
  FAMILY_COLOR[f ?? ''] ?? 'var(--color-ink-faint)'

export const TIER_COLOR: Record<string, string> = {
  S: 'var(--color-ready)', A: 'var(--color-tops)', B: 'var(--color-wip)',
  C: 'var(--color-ink-faint)', D: 'var(--color-blocked)',
}
