import { describe, expect, it } from "vitest";
import { BLOCKBREAKER_BRICK_COLORS } from "./blockbreaker";
import {
  BLOCKBREAKER_BIOMES,
  BLOCKBREAKER_BIOME_IDS,
  blockbreakerBiomeForSeed,
} from "./blockbreakerBiomes";

describe("Blockbreaker arena biomes", () => {
  it("defines five distinct arena and fixture styles", () => {
    expect(BLOCKBREAKER_BIOMES.map((biome) => biome.id)).toEqual(BLOCKBREAKER_BIOME_IDS);
    expect(new Set(BLOCKBREAKER_BIOMES.map((biome) => biome.name)).size).toBe(5);
    expect(new Set(BLOCKBREAKER_BIOMES.map((biome) => biome.fixture)).size).toBe(5);
    expect(new Set(BLOCKBREAKER_BIOMES.map((biome) => biome.background)).size).toBe(5);
    expect(new Set(BLOCKBREAKER_BIOMES.map((biome) => biome.keyLight)).size).toBe(5);
  });

  it("keeps every gameplay brick color visually distinct in every biome", () => {
    for (const biome of BLOCKBREAKER_BIOMES) {
      const colors = BLOCKBREAKER_BRICK_COLORS.map((color) => biome.bricks[color]);
      expect(colors.every((color) => /^#[0-9a-f]{6}$/i.test(color))).toBe(true);
      expect(new Set(colors).size).toBe(BLOCKBREAKER_BRICK_COLORS.length);
    }
  });

  it("selects a deterministic biome from the match seed", () => {
    expect(blockbreakerBiomeForSeed(0x12345678)).toBe(blockbreakerBiomeForSeed(0x12345678));
    const sampledIds = new Set(Array.from({ length: 256 }, (_, seed) => blockbreakerBiomeForSeed(seed).id));
    expect(sampledIds).toEqual(new Set(BLOCKBREAKER_BIOME_IDS));
  });
});
