<?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::create('payment_methods', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->string('slug')->unique();
            $table->timestamps();
        });

        Schema::create('available_payment_methods', function (Blueprint $table) {
            $table->id();
            $table->string('tenant');
            $table->string('slug');
            $table->string('name');
            $table->string('description')->nullable();
            $table->boolean('active')->default(true);
            $table->timestamps();

            $table->foreign('tenant')->references('slug')->on('tenants')->restrictOnDelete()->cascadeOnUpdate();
            $table->foreign('slug')->references('slug')->on('payment_methods')->restrictOnDelete()->cascadeOnUpdate();
            $table->unique(['tenant', 'slug']);
        });
    }

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