<?php
declare(strict_types=1);
// ==================================================
// Nuclear Fancy Pants Edition™ — NUCLEAR+++
// File: /migrations/007_unsplash_image.php
// Description: Adds unsplash_attachment_id and unsplash_credit columns to wp_amai_scheduled_posts - NUCLEAR+++
// Last Edited: 2026-04-01
// ==================================================
namespace AutoMarketerAI\Migrations;
defined('ABSPATH') || exit;
final class Migration_007_UnsplashImage
{
    public const VERSION     = '007';
    public const DESCRIPTION = 'Add unsplash_attachment_id and unsplash_credit columns to scheduled posts';
    public function up(): void
    {
        global $wpdb;
        $table = $wpdb->prefix . 'amai_scheduled_posts';
        $has_attachment_id = $wpdb->get_results(
            "SHOW COLUMNS FROM {$table} LIKE 'unsplash_attachment_id'"
        );
        if (empty($has_attachment_id)) {
            $wpdb->query(
                "ALTER TABLE {$table}
                 ADD COLUMN unsplash_attachment_id bigint(20) NULL DEFAULT NULL
                 AFTER feeling"
            );
        }
        $has_credit = $wpdb->get_results(
            "SHOW COLUMNS FROM {$table} LIKE 'unsplash_credit'"
        );
        if (empty($has_credit)) {
            $wpdb->query(
                "ALTER TABLE {$table}
                 ADD COLUMN unsplash_credit varchar(512) NULL DEFAULT NULL
                 AFTER unsplash_attachment_id"
            );
        }
    }
    public function down(): void
    {
        global $wpdb;
        $table = $wpdb->prefix . 'amai_scheduled_posts';
        $wpdb->query("ALTER TABLE {$table} DROP COLUMN IF EXISTS unsplash_credit");
        $wpdb->query("ALTER TABLE {$table} DROP COLUMN IF EXISTS unsplash_attachment_id");
    }
}