<?php
declare(strict_types=1);
// ==================================================
// Nuclear Fancy Pants Edition™ — NUCLEAR+++
// File: /migrations/018_bounces_table.php
// Description: Creates wp_amai_bounces table for hard bounce logging - NUCLEAR+++
// Last Edited: 2026-04-18
// ==================================================
namespace AutoMarketerAI\Migrations;

defined('ABSPATH') || exit;

final class Migration_018_BouncesTable
{
    // Migration version identifier -- never change once shipped
    public const VERSION = '018';
    public const DESCRIPTION = 'Create wp_amai_bounces table for hard bounce logging';

    public function up(): void
    {
        global $wpdb;
        $table   = $wpdb->prefix . 'amai_bounces';
        $charset = $wpdb->get_charset_collate();
        // DDL auto-commits in MySQL -- no transaction wrapper needed
        $wpdb->query(
            "CREATE TABLE IF NOT EXISTS {$table} (
                id          BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
                email       VARCHAR(255)    NOT NULL,
                bounce_type VARCHAR(64)     NOT NULL,
                raw_status  VARCHAR(64)     NOT NULL DEFAULT '',
                bounced_at  DATETIME        NOT NULL,
                PRIMARY KEY (id),
                KEY idx_email (email),
                KEY idx_bounced_at (bounced_at)
            ) {$charset}"
        );
    }

    public function down(): void
    {
        // Forward-only migrations -- down() documents intent only.
        // Never call this in production.
        // To rollback: DROP TABLE IF EXISTS {prefix}amai_bounces;
    }
}