import { describe, expect, it } from 'vitest';
import { VoxelWorld } from '../../world/world';
import { encodeModel } from '../format';
import { VoxelGrid } from '../../voxel/grid';
import { stampModel } from '../stamp';

/** Модель 1×1×1 с одним тайлем (id 3) на вокселе. */
function texturedModel(): ReturnType<typeof encodeModel> {
    const g = new VoxelGrid(1, 1, 1);
    g.set(0, 0, 0, 1);
    const face = btoa(String.fromCharCode(2, 2, 2, 2)); // size 2, слот 2
    return encodeModel(g, { 1: '#808080', 2: '#c0c0c0' }, {
        tiles: { 3: { size: 2, faces: [face, face, face, face, face, face] } },
        tex: new Uint8Array([3]),
    });
}

describe('stampModel со слоем тайлей (texRemap)', () => {
    it('штампует мировой id тайля через переводчик', () => {
        const w = new VoxelWorld(4);
        const m = texturedModel();
        stampModel(w, m, 1, 0, 1, {}, { texRemap: (id: number) => id + 100 });
        expect(w.get(1, 0, 1)).toBe(1);
        expect(w.getTex(1, 0, 1)).toBe(103);
  });

    it('без texRemap слой тайлей не пишется', () => {
        const w = new VoxelWorld(4);
        stampModel(w, texturedModel(), 0, 0, 0);
        expect(w.get(0, 0, 0)).toBe(1);
        expect(w.getTex(0, 0, 0)).toBe(0);
    });
});
