const responses = ["wink", "double blink", "close your eyes", "jump"] as const;

export function commands(secret: Secret): Response[] {
  if (secret < 1 || secret > 31) {
    return [];
  }

  const result = secret
    .toString(2)
    .split("")
    .reverse()
    .map((s, i) => (s === "1" ? responses[i] : null))
    .filter(Boolean);

  if (secret >= 16) {
    return result.reverse() as Response[];
  }
  return result as Response[];
}

type Secret =
  | 1
  | 2
  | 3
  | 4
  | 5
  | 6
  | 7
  | 8
  | 9
  | 10
  | 11
  | 12
  | 13
  | 14
  | 15
  | 16
  | 17
  | 18
  | 19
  | 20
  | 21
  | 22
  | 23
  | 24
  | 25
  | 26
  | 27
  | 28
  | 29
  | 30
  | 31;

type Response = typeof responses[number];
