<?php

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

return new class extends Migration
{
    public function up(): void
    {
        // Snapshot columns for the automatic cart-value discount (Spend &
        // Save). The single `discount` column already holds the total of every
        // discount source; these two let a receipt break the cart-rule share
        // back out by name without touching the ledger-based voucher/loyalty
        // reconstruction in InvoiceDocument::discountBreakdown().
        Schema::table('invoices', function (Blueprint $table) {
            $table->decimal('cart_discount_amount', 14, 2)->default(0)->after('discount');
            $table->string('cart_discount_name', 150)->nullable()->after('cart_discount_amount');
        });
    }

    public function down(): void
    {
        Schema::table('invoices', function (Blueprint $table) {
            $table->dropColumn(['cart_discount_amount', 'cart_discount_name']);
        });
    }
};
