<?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('personeros', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->nullable()->unique()->constrained()->nullOnDelete();
            $table->foreignId('political_party_id')->constrained()->cascadeOnDelete();
            $table->foreignId('voting_table_id')->nullable()->constrained()->nullOnDelete();
            $table->string('first_name');
            $table->string('last_name');
            $table->char('dni', 8)->unique();
            $table->string('phone', 20)->nullable();
            $table->enum('function', ['titular', 'alterno', 'de_local'])->default('titular');
            $table->enum('status', ['active', 'inactive'])->default('active');
            $table->text('observations')->nullable();
            $table->timestamps();
            $table->softDeletes();

            $table->index('political_party_id');
            $table->index('voting_table_id');
        });
    }

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