import { GoogleTms, Nztm2000Tms, ImageFormat } from '@basemaps/geo';
import { TileType } from '@basemaps/shared';
import { TestTiff } from '@basemaps/test';
import o from 'ospec';
import { TileEtag } from '../routes/tile.etag.js';
o.spec('TileCacheKey', () => {
    const oldRenderId = TileEtag.RenderId;
    const xyzData = {
        x: 0,
        y: 0,
        z: 0,
        tileMatrix: GoogleTms,
        name: 'foo',
        ext: ImageFormat.Png,
        type: TileType.Tile,
    };
    o.afterEach(() => {
        TileEtag.RenderId = oldRenderId;
    });
    o('should generate a cachekey', async () => {
        const tiff = await TestTiff.Google.init();
        const comp = {
            tiff,
            source: {
                x: 0,
                y: 0,
                imageId: 0,
                width: 512,
                height: 512,
            },
            x: 5,
            y: 5,
        };
        const firstKey = TileEtag.generate([comp], xyzData);
        o(firstKey).equals('8eJ7XnUeEGBI2d7mfAaK5o8KbUc0+CVaIoPzqCvkoDk=');
        // Different layers should generate different keys
        o(TileEtag.generate([comp, comp], xyzData)).notEquals(firstKey);
        // Different projections should generate different keys
        xyzData.tileMatrix = Nztm2000Tms;
        o(TileEtag.generate([comp], xyzData)).notEquals(firstKey);
    });
    o('should change if the renderId changes', () => {
        const keyA = TileEtag.generate([], { tileMatrix: {} });
        TileEtag.RenderId = 2;
        const KeyB = TileEtag.generate([], { tileMatrix: {} });
        o(keyA).notEquals(KeyB);
    });
});
