<?php

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

/**
 * Where the budget sits, and what kind of budget it is.
 *
 * There was one budget column and it meant exactly one thing: a daily amount on
 * the ad set. Meta offers two axes and SERP-1833 names both. Advantage campaign
 * budget (CBO) puts the money on the campaign and lets Meta move it between ad
 * sets; ad set budget (ABO) holds each ad set to its own. Separately a budget is
 * either daily or lifetime, and lifetime is the only way to say "spend this much
 * in total by this date".
 *
 * Nullable with no default, so a campaign nobody asked about is distinguishable
 * from one where somebody chose the ordinary arrangement. Null is read as a
 * daily ad set budget everywhere, which is what every campaign published so far
 * was, so nothing already in the table changes meaning.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('campaigns', function (Blueprint $table): void {
            // 'adset' or 'campaign'. Named for the level the money sits at
            // rather than for Meta's marketing, which renames these regularly.
            $table->string('budget_level', 16)->nullable()->after('budget');

            // 'daily' or 'lifetime'.
            $table->string('budget_mode', 16)->nullable()->after('budget_level');
        });
    }

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