-- Create tiles table to store successful PMTiles processing results
CREATE TABLE IF NOT EXISTS tiles (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user_id INT NOT NULL,
    job_id VARCHAR(255) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    type ENUM('vector', 'raster') NOT NULL DEFAULT 'vector',
    layer_names TEXT,
    layer_properties JSON,
    tilejson_url VARCHAR(500),
    original_filename VARCHAR(255),
    unique_filename VARCHAR(255) NOT NULL,
    file_size BIGINT,
    bounds TEXT,
    min_zoom INT,
    max_zoom INT,
    feature_count INT,
    layer_count INT DEFAULT 0,
    tile_type VARCHAR(50),
    data_type VARCHAR(50),
    conversion_seconds DECIMAL(10,3),
    size_reduction_percent DECIMAL(5,2),
    converter VARCHAR(100),
    status ENUM('completed', 'error') DEFAULT 'completed',
    maputnik_url VARCHAR(500),
    pmtiles_url VARCHAR(500),
    
    INDEX idx_user_id (user_id),
    INDEX idx_job_id (job_id),
    INDEX idx_created_at (created_at),
    INDEX idx_type (type),
    INDEX idx_status (status),
    
    UNIQUE KEY unique_user_filename (user_id, unique_filename)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
