-- Platform cleanup: open casino/forex, remove obsolete unlock rules, developer keys, hide tournaments

-- Remove subscription gates on casino and forex (bet/trade freely; academy gated separately)
DELETE ur FROM unlock_rules ur
JOIN modules m ON m.id = ur.module_id
WHERE m.slug IN ('casino', 'forex');

-- Ensure modules are enabled
UPDATE modules SET status = 'enabled' WHERE slug IN ('casino', 'forex', 'football', 'social_media', 'social_posts', 'ads');

-- Remove socialmedis hub (consolidated into social hubs)
DELETE FROM modules WHERE slug = 'socialmedis';

-- Developer API keys for social posting integrations
CREATE TABLE IF NOT EXISTS user_developer_keys (
    id           INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    user_id      INT UNSIGNED NOT NULL,
    label        VARCHAR(80) NOT NULL DEFAULT 'Default',
    api_key      VARCHAR(64) NOT NULL,
    api_secret   VARCHAR(128) NOT NULL,
    scopes       SET('post','like','read') NOT NULL DEFAULT 'post,like,read',
    status       ENUM('active','revoked') NOT NULL DEFAULT 'active',
    last_used_at DATETIME NULL,
    created_at   DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
    UNIQUE KEY uk_api_key (api_key),
    INDEX idx_user (user_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
