get_charset_collate(); $prefix = $wpdb->prefix; return array( self::get_point_types_table_schema($prefix, $charset_collate), self::get_achievements_table_schema($prefix, $charset_collate), self::get_levels_table_schema($prefix, $charset_collate), self::get_requirements_table_schema($prefix, $charset_collate), self::get_requirement_progress_table_schema($prefix, $charset_collate), self::get_points_log_table_schema($prefix, $charset_collate), self::get_user_achievements_table_schema($prefix, $charset_collate), self::get_user_levels_table_schema($prefix, $charset_collate), self::get_logs_table_schema($prefix, $charset_collate), self::get_notifications_table_schema($prefix, $charset_collate), self::get_rewards_table_schema($prefix, $charset_collate), self::get_reward_redemptions_table_schema($prefix, $charset_collate), self::get_gift_claims_table_schema($prefix, $charset_collate), ); } private static function get_point_types_table_schema($prefix, $charset_collate) { return "CREATE TABLE {$prefix}gameengine_point_types ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(255) NOT NULL, plural_name VARCHAR(255) NOT NULL, status VARCHAR(20) DEFAULT 'publish', slug VARCHAR(255) NOT NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY slug (slug) ) $charset_collate;"; } private static function get_achievements_table_schema($prefix, $charset_collate) { return "CREATE TABLE {$prefix}gameengine_achievements ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, title VARCHAR(255) NOT NULL, plural_name VARCHAR(255) DEFAULT NULL, slug VARCHAR(255) DEFAULT NULL, status VARCHAR(20) DEFAULT 'publish', badge_image VARCHAR(255), badge_id BIGINT(20) UNSIGNED DEFAULT NULL, category VARCHAR(255) DEFAULT NULL, congratulations_message TEXT DEFAULT NULL, description TEXT DEFAULT NULL, secret_achievement TINYINT(1) DEFAULT 0, max_earnings_per_user INT(11) DEFAULT 0, unlock_with_points_enabled TINYINT(1) DEFAULT 0, is_restricted TINYINT(1) DEFAULT 0, required_point_type_id BIGINT(20) UNSIGNED DEFAULT NULL, required_points_amount INT(11) DEFAULT 0, required_achievement_id BIGINT(20) UNSIGNED DEFAULT NULL, required_level_id BIGINT(20) UNSIGNED DEFAULT NULL, restriction_message TEXT DEFAULT NULL, season_id BIGINT(20) UNSIGNED DEFAULT NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY slug (slug), KEY required_point_type_id (required_point_type_id), KEY required_achievement_id (required_achievement_id), KEY required_level_id (required_level_id) ) $charset_collate;"; } private static function get_levels_table_schema($prefix, $charset_collate) { return "CREATE TABLE {$prefix}gameengine_levels ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, title VARCHAR(255) NOT NULL, plural_name VARCHAR(255), slug VARCHAR(255) DEFAULT NULL, status VARCHAR(20) DEFAULT 'publish', description TEXT, icon VARCHAR(255), color VARCHAR(7) NOT NULL DEFAULT '#6c5ce7', category VARCHAR(255) DEFAULT NULL, priority INT(11) NOT NULL DEFAULT 0, unlock_with_points_enabled TINYINT(1) DEFAULT 0, is_restricted TINYINT(1) DEFAULT 0, point_type_id BIGINT(20) UNSIGNED DEFAULT NULL, min_points INT(11) DEFAULT 0, max_points INT(11) DEFAULT 0, congratulations_message TEXT DEFAULT NULL, required_achievement_id BIGINT(20) UNSIGNED DEFAULT NULL, required_level_id BIGINT(20) UNSIGNED DEFAULT NULL, restriction_message TEXT DEFAULT NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY point_type_id (point_type_id), KEY required_achievement_id (required_achievement_id), KEY required_level_id (required_level_id) ) $charset_collate;"; } private static function get_requirements_table_schema($prefix, $charset_collate) { return "CREATE TABLE {$prefix}gameengine_requirements ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, reward_type VARCHAR(50) NOT NULL, reward_id BIGINT(20) UNSIGNED NOT NULL, trigger_key VARCHAR(255) NOT NULL, action_type ENUM('award', 'deduct') NOT NULL DEFAULT 'award', parameters JSON, priority INT(11) NOT NULL DEFAULT 0, is_active TINYINT(1) NOT NULL DEFAULT 1, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY reward_lookup (reward_type, reward_id), KEY trigger_lookup (trigger_key) ) $charset_collate;"; } private static function get_requirement_progress_table_schema($prefix, $charset_collate) { return "CREATE TABLE {$prefix}gameengine_requirement_progress ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, user_id BIGINT(20) UNSIGNED NOT NULL, requirement_id BIGINT(20) UNSIGNED NOT NULL, progress_count INT(11) NOT NULL DEFAULT 0, streak_count INT(11) NOT NULL DEFAULT 0, streak_best INT(11) NOT NULL DEFAULT 0, streak_last_at DATETIME DEFAULT NULL, last_updated DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY user_requirement (user_id, requirement_id) ) $charset_collate;"; } private static function get_points_log_table_schema($prefix, $charset_collate) { return "CREATE TABLE {$prefix}gameengine_points_log ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, user_id BIGINT(20) UNSIGNED NOT NULL, point_type_id BIGINT(20) UNSIGNED NOT NULL, points INT(11) NOT NULL, context VARCHAR(100) NOT NULL, requirement_id BIGINT(20) UNSIGNED DEFAULT NULL, description TEXT, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY user_id (user_id), KEY point_type_id (point_type_id), KEY type_date (point_type_id, created_at) ) $charset_collate;"; } private static function get_user_achievements_table_schema($prefix, $charset_collate) { return "CREATE TABLE {$prefix}gameengine_user_achievements ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, user_id BIGINT(20) UNSIGNED NOT NULL, achievement_id BIGINT(20) UNSIGNED NOT NULL, achieved_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY user_id (user_id), KEY achievement_id (achievement_id) ) $charset_collate;"; } private static function get_user_levels_table_schema($prefix, $charset_collate) { return "CREATE TABLE {$prefix}gameengine_user_levels ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, user_id BIGINT(20) UNSIGNED NOT NULL, level_id BIGINT(20) UNSIGNED NOT NULL, achieved_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY user_level (user_id, level_id), KEY level_id (level_id) ) $charset_collate;"; } private static function get_logs_table_schema($prefix, $charset_collate) { return "CREATE TABLE {$prefix}gameengine_logs ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, user_id BIGINT(20) UNSIGNED DEFAULT NULL, trigger_key VARCHAR(255) NOT NULL, status ENUM('success','failed','skipped') NOT NULL, points_awarded INT(11) DEFAULT 0, message TEXT, meta JSON, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY user_id (user_id), KEY trigger_key (trigger_key) ) $charset_collate;"; } private static function get_notifications_table_schema($prefix, $charset_collate) { return "CREATE TABLE {$prefix}gameengine_notifications ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, user_id BIGINT(20) UNSIGNED NOT NULL, type VARCHAR(50) NOT NULL DEFAULT 'points', message TEXT NOT NULL, is_read TINYINT(1) NOT NULL DEFAULT 0, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY user_id (user_id), KEY is_read (is_read) ) $charset_collate;"; } private static function get_rewards_table_schema($prefix, $charset_collate) { return "CREATE TABLE {$prefix}gameengine_rewards ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, title VARCHAR(255) NOT NULL, slug VARCHAR(255) NOT NULL, description TEXT DEFAULT NULL, image VARCHAR(255) DEFAULT NULL, cost_points INT(11) NOT NULL DEFAULT 0, point_type_id BIGINT(20) UNSIGNED DEFAULT NULL, stock INT(11) NOT NULL DEFAULT -1, limit_per_user INT(11) NOT NULL DEFAULT 0, status VARCHAR(20) DEFAULT 'publish', created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY slug (slug), KEY point_type_id (point_type_id) ) $charset_collate;"; } private static function get_reward_redemptions_table_schema($prefix, $charset_collate) { return "CREATE TABLE {$prefix}gameengine_reward_redemptions ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, user_id BIGINT(20) UNSIGNED NOT NULL, reward_id BIGINT(20) UNSIGNED NOT NULL, points_spent INT(11) NOT NULL DEFAULT 0, status VARCHAR(20) NOT NULL DEFAULT 'completed', created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY user_id (user_id), KEY reward_id (reward_id) ) $charset_collate;"; } private static function get_gift_claims_table_schema($prefix, $charset_collate) { return "CREATE TABLE {$prefix}gameengine_gift_claims ( id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT, claim_token VARCHAR(64) NOT NULL, order_id BIGINT(20) UNSIGNED NOT NULL, order_item_id BIGINT(20) UNSIGNED NOT NULL, buyer_user_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 0, recipient_email VARCHAR(255) NOT NULL, recipient_name VARCHAR(255) DEFAULT '', point_type_id BIGINT(20) UNSIGNED NOT NULL DEFAULT 1, points INT(11) NOT NULL DEFAULT 0, message TEXT DEFAULT NULL, status VARCHAR(20) NOT NULL DEFAULT 'pending', claimed_by_user_id BIGINT(20) UNSIGNED DEFAULT NULL, claimed_at DATETIME DEFAULT NULL, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY claim_token (claim_token), KEY recipient_email (recipient_email), KEY order_id (order_id), KEY status (status) ) $charset_collate;"; } }