<?php

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

/**
 * How much of what was charged at the checkout was the one-off setup fee.
 *
 * The fee has been on the public price sheet and on the booking page for months
 * — "zzgl. Einrichtung einmalig", and since the gross-pricing work with the
 * figure named — and it was never charged to anybody. The operator sets it in
 * the console, two pages read it out to quote it, and nothing put it on a bill.
 * A price advertised and not taken is a smaller problem than one taken and not
 * advertised, but it is the same class of problem: the page and the money have
 * to say the same thing.
 *
 * It is charged now, as a one-off line on the Stripe checkout session beside the
 * recurring one — which Stripe puts on the initial invoice only, which is exactly
 * what a setup fee is. That makes the session's `amount_total`, and therefore the
 * order's `amount_cents`, the package's gross PLUS the fee, and this column is
 * what lets the two be told apart again afterwards.
 *
 * Why it matters that they can: `amount_cents` is what a withdrawal refunds and
 * what the confirmation mail states, and both of those want the whole of what was
 * taken. But the proof register holds the charge against the CONTRACT's agreed
 * price, and the invoice needs the fee as a line of its own rather than folded
 * silently into the package's — so everything that reasons about the package
 * subtracts this, through Order::packageChargedCents().
 *
 * Zero, not null, and no backfill: every order that already exists was charged no
 * setup fee, and zero is the truth about them rather than a placeholder.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('orders', function (Blueprint $table) {
            $table->unsignedInteger('setup_fee_cents')->default(0)->after('amount_cents');
        });
    }

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