<?php
declare(strict_types=1);
// ==================================================
// Nuclear Fancy Pants Edition™ — NUCLEAR+++
// File: /home/ploi/automarketer-ai.com/public/wp-content/plugins/automarketer-ai/migrations/027_outbound_links.php
// Description: Creates wp_amai_outbound_links table for curated outbound link suggestions - NUCLEAR+++
// Last Edited: 2026-05-01
// ==================================================
namespace AutoMarketerAI\Migrations;
defined('ABSPATH') || exit;
class Migration_027_OutboundLinks
{
    public function up(): void
    {
        global $wpdb;
        $table  = $wpdb->prefix . 'amai_outbound_links';
        $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,
            keyword       VARCHAR(128)    NOT NULL,
            url           VARCHAR(512)    NOT NULL,
            anchor        VARCHAR(128)    NOT NULL,
            source        VARCHAR(64)     NOT NULL DEFAULT 'manual',
            active        TINYINT(1)      NOT NULL DEFAULT 1,
            created_at    DATETIME        NOT NULL,
            PRIMARY KEY (id),
            KEY idx_keyword (keyword),
            KEY idx_active  (active)
        ) {$charset};";
        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        dbDelta($sql);
    }
}