<?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('sepa_payment_elements', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->string('tenant');
            $table->foreignId('invoice_id')->constrained('invoices', 'id')->restrictOnDelete()->cascadeOnUpdate();
            $table->foreignId('cost_unit_id')->constrained('cost_units', 'id')->restrictOnDelete()->cascadeOnUpdate();
            $table->float('amount', 2);
            $table->string('recipient_name');
            $table->string('recipient_iban');
            $table->string('payment_purpose');
            $table->boolean('exported')->default(false);
            $table->dateTime('exported_at')->nullable();

            $table->foreign('tenant')->references('slug')->on('tenants')->restrictOnDelete()->cascadeOnUpdate();

            $table->timestamps();
        });
    }

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