<?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('tenant_integration', function (Blueprint $table) {
            $table->id();
            $table->string('integration_code');
            $table->string('tenant_code');
            $table->longText('integration_data')->nullable(); // Stored as longText because it's encrypted JSON
            $table->timestamps();

            // Foreign keys
            $table->foreign('integration_code')->references('integration_code')->on('integrations')->onDelete('cascade');
            $table->foreign('tenant_code')->references('codigo')->on('tenants')->onDelete('cascade');

            $table->unique(['integration_code', 'tenant_code']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('tenant_integration');
    }
};
