<?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('responsibles', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('phone');
            $table->timestamps();
            $table->softDeletes();
        });
        Schema::table('areas', function (Blueprint $table) {
            $table->foreignId('responsible_id')
                ->nullable()
                ->after('district_id')
                ->constrained('responsibles')
                ->nullOnDelete();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('areas', function (Blueprint $table) {
            $table->dropForeign('areas_responsible_id_foreign');
            $table->dropColumn('responsible_id');
        });
        Schema::dropIfExists('responsibles');
    }
};
