<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

/**
 * When a campaign was set running on the platform.
 *
 * Every platform is built paused: Meta and Google create PAUSED at every level,
 * and LinkedIn creates DRAFT. Publishing assembles a campaign and stops. Starting
 * it is a separate decision, asked for in the chat and approved on its own,
 * because publishing and spending are not the same act.
 *
 * Nothing recorded which of those two a campaign was in. `status` holds draft,
 * published or failed, so a campaign parked on the account and one spending money
 * looked identical in the database, on the panel and to the chat - and an activate
 * step would have had nowhere to write and no way to be idempotent.
 *
 * A timestamp rather than a flag, because "since when" is a question anyone
 * looking at spend will ask. Null means built and parked, which is every campaign
 * that exists today and the state every new one starts in. Pausing clears it; the
 * history of both lives in campaign_changes.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('campaigns', function (Blueprint $table) {
            $table->timestamp('activated_at')->nullable()->after('external_ids');
        });
    }

    public function down(): void
    {
        Schema::table('campaigns', function (Blueprint $table) {
            $table->dropColumn('activated_at');
        });
    }
};
