<?php
declare(strict_types=1);
// ==================================================
// Nuclear Fancy Pants Edition™ — NUCLEAR+++
// File: /home/ploi/automarketer-ai.com/public/wp-content/plugins/automarketer-ai/migrations/026_nudge_log.php
// Description: Creates wp_amai_nudge_log table for profile completion nudge tracking - NUCLEAR+++
// Last Edited: 2026-04-29
// ==================================================

namespace AutoMarketerAI\Migrations;

defined('ABSPATH') || exit;

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

        $table  = $wpdb->prefix . 'amai_nudge_log';
        $exists = $wpdb->get_var("SHOW TABLES LIKE '{$table}'");

        if ($exists === $table) {
            return;
        }

        $charset = $wpdb->get_charset_collate();

        $sql = "CREATE TABLE {$table} (
            id            BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
            nudge_key     VARCHAR(64)     NOT NULL,
            first_seen_at DATETIME        NOT NULL,
            email_sent_at DATETIME            NULL DEFAULT NULL,
            snoozed_until DATETIME            NULL DEFAULT NULL,
            PRIMARY KEY (id),
            UNIQUE KEY uq_nudge_key (nudge_key)
        ) {$charset};";

        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        dbDelta($sql);
    }
}