<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::table('checkout_sessions', function (Blueprint $table) {
            $table->foreignIdFor(\App\Models\Coupon::class)->nullable()->after('package_snapshot')->constrained()->nullOnDelete();
            $table->string('coupon_code')->nullable()->after('coupon_id');
            $table->json('coupon_snapshot')->nullable()->after('coupon_code');

            $table->decimal('amount_discount', 10, 2)->default(0)->after('amount_total');
            $table->json('discount_breakdown')->nullable()->after('amount_discount');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('checkout_sessions', function (Blueprint $table) {
            $table->dropConstrainedForeignId('coupon_id');
            $table->dropColumn(['coupon_code', 'coupon_snapshot', 'amount_discount', 'discount_breakdown']);
        });
    }
};
