<?php
declare(strict_types=1);
// ==================================================
// Nuclear Fancy Pants Edition™ -- NUCLEAR+++
// File: /home/ploi/automarketer-ai.com/public/wp-content/plugins/automarketer-ai/migrations/035_wp_comment_id.php
// Description: Adds wp_comment_id column to wp_amai_social_comments for WordPress and WooCommerce comment mapping - NUCLEAR+++
// Last Edited: 2026-05-15
// ==================================================

namespace AutoMarketerAI\Migrations;

defined('ABSPATH') || exit;

class Migration_035_WpCommentId
{
    public function up(): void
    {
        global $wpdb;

        $table = $wpdb->prefix . 'amai_social_comments';

        // Idempotent -- skip if column already exists.
        $exists = $wpdb->get_var(
            $wpdb->prepare(
                "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
                 WHERE TABLE_SCHEMA = %s AND TABLE_NAME = %s AND COLUMN_NAME = 'wp_comment_id'",
                DB_NAME,
                $table
            )
        );

        if ((int) $exists > 0) {
            return;
        }

        $wpdb->query(
            "ALTER TABLE `{$table}`
             ADD COLUMN `wp_comment_id` BIGINT UNSIGNED NULL DEFAULT NULL AFTER `reply_to_comment_id`"
        );
    }
}