<?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
    {
        Schema::create('event_package_addons', function (Blueprint $table) {
            $table->id();
            $table->foreignId('event_package_id')->constrained()->cascadeOnDelete();
            $table->foreignId('event_id')->constrained()->cascadeOnDelete();
            $table->foreignId('tenant_id')->constrained()->cascadeOnDelete();
            $table->string('addon_key');
            $table->integer('quantity')->default(1);
            $table->integer('extra_photos')->default(0);
            $table->integer('extra_guests')->default(0);
            $table->integer('extra_gallery_days')->default(0);
            $table->string('price_id')->nullable();
            $table->string('checkout_id')->nullable();
            $table->string('transaction_id')->nullable();
            $table->enum('status', ['pending', 'completed', 'failed'])->default('pending');
            $table->decimal('amount', 10, 2)->nullable();
            $table->string('currency', 3)->nullable();
            $table->json('metadata')->nullable();
            $table->json('receipt_payload')->nullable();
            $table->string('error')->nullable();
            $table->timestamp('purchased_at')->nullable();
            $table->timestamps();

            $table->index(['tenant_id', 'event_id']);
            $table->index(['checkout_id']);
            $table->index(['transaction_id']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('event_package_addons');
    }
};
