/**
 * Generic utility types used across the codebase.
 */

/** Recursively makes all properties readonly. */
export type DeepImmutable<T> =
  T extends Map<infer K, infer V>
    ? ReadonlyMap<DeepImmutable<K>, DeepImmutable<V>>
    : T extends Set<infer V>
      ? ReadonlySet<DeepImmutable<V>>
      : T extends (infer V)[]
        ? readonly DeepImmutable<V>[]
        : T extends object
          ? { readonly [K in keyof T]: DeepImmutable<T[K]> }
          : T

/** Generate all permutations of a string union as space-separated strings. */
export type Permutations<T extends string, U extends string = T> = T extends unknown
  ? T | `${T} ${Permutations<Exclude<U, T>>}`
  : never
