/**
 * The 8 symmetries of the 3×3 board (dihedral group D4) — the spec's "fixed set of 8 balanced layouts".
 * Keys, order (symmetry index 0..7) and permutations must match SYMMETRIES in packages/engine/src/board.ts;
 * see docs/ARCHITECTURE.md §2.1. `permutation[p]` is the board cell that base cell `p` moves to.
 */

export interface BoardTemplateDef {
  key: string;
  name: string;
  symmetry: number;
  permutation: number[];
}

type CellMap = (r: number, c: number) => [number, number];

const TRANSFORMS: readonly { key: string; name: string; map: CellMap }[] = [
  { key: 'identity', name: 'Identity', map: (r, c) => [r, c] },
  { key: 'rot90', name: 'Rotate 90°', map: (r, c) => [c, 2 - r] },
  { key: 'rot180', name: 'Rotate 180°', map: (r, c) => [2 - r, 2 - c] },
  { key: 'rot270', name: 'Rotate 270°', map: (r, c) => [2 - c, r] },
  { key: 'mirror-lr', name: 'Mirror left–right', map: (r, c) => [r, 2 - c] },
  { key: 'mirror-tb', name: 'Mirror top–bottom', map: (r, c) => [2 - r, c] },
  { key: 'transpose', name: 'Transpose', map: (r, c) => [c, r] },
  { key: 'anti-transpose', name: 'Anti-transpose', map: (r, c) => [2 - c, 2 - r] },
];

export const BOARD_TEMPLATES: readonly BoardTemplateDef[] = TRANSFORMS.map(({ key, name, map }, symmetry) => ({
  key,
  name,
  symmetry,
  permutation: Array.from({ length: 9 }, (_, p) => {
    const [r, c] = map(Math.floor(p / 3), p % 3);
    return r * 3 + c;
  }),
}));
