<?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('service_contents', function (Blueprint $table) {
            $table->unsignedBigInteger('site_management_component_field_id')->nullable();
            $table->unsignedBigInteger('site_management_field_type_id')->nullable();

            // Definindo as chaves estrangeiras
            $table->foreign('site_management_component_field_id')
                ->references('id')->on('site_management_component_fields')
                ->onDelete('set null'); // Ou 'cascade', dependendo do comportamento desejado

            $table->foreign('site_management_field_type_id')
                ->references('id')->on('site_management_field_types')
                ->onDelete('set null'); // Ou 'cascade'
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('service_contents', function (Blueprint $table) {
            $table->dropForeign(['site_management_component_field_id']);
            $table->dropForeign(['site_management_field_type_id']);
            $table->dropColumn('site_management_component_field_id');
            $table->dropColumn('site_management_field_type_id');
        });
    }
};
