-- Minimap tiles table storing processed WebP images
CREATE TABLE minimap_tiles (
    id INTEGER PRIMARY KEY AUTOINCREMENT,

    -- Tile coordinates (matching file naming: x_y.png)
    x INTEGER NOT NULL,
    y INTEGER NOT NULL,

    -- Original PNG metadata
    original_width INTEGER NOT NULL DEFAULT 512,
    original_height INTEGER NOT NULL DEFAULT 512,
    original_file_size INTEGER,

    -- WebP blobs at different resolutions
    webp_512 BLOB NOT NULL,      -- 512x512 WebP
    webp_256 BLOB NOT NULL,      -- 256x256 WebP
    webp_128 BLOB NOT NULL,      -- 128x128 WebP
    webp_64 BLOB NOT NULL,       -- 64x64 WebP

    -- Blob sizes for quick reference
    webp_512_size INTEGER NOT NULL,
    webp_256_size INTEGER NOT NULL,
    webp_128_size INTEGER NOT NULL,
    webp_64_size INTEGER NOT NULL,

    -- Processing metadata
    processed_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    source_path TEXT NOT NULL,

    -- Ensure unique coordinate pairs
    UNIQUE(x, y)
);

-- Index for fast coordinate lookups
CREATE INDEX idx_minimap_coords ON minimap_tiles(x, y);

-- Index for boundary queries
CREATE INDEX idx_minimap_x ON minimap_tiles(x);
CREATE INDEX idx_minimap_y ON minimap_tiles(y);
