<?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::table('personeros', function (Blueprint $table) {
            $table->enum('scope', ['departamental', 'provincial', 'distrital', 'local', 'mesa'])
                  ->default('mesa')->after('function');
            $table->foreignId('department_id')->nullable()->constrained()->nullOnDelete()->after('voting_table_id');
            $table->foreignId('province_id')->nullable()->constrained()->nullOnDelete()->after('department_id');
            $table->foreignId('district_id')->nullable()->constrained()->nullOnDelete()->after('province_id');
            $table->foreignId('voting_location_id')->nullable()->constrained()->nullOnDelete()->after('district_id');
            $table->enum('attendance', ['pending', 'present', 'absent'])->default('pending')->after('status');
        });
    }

    public function down(): void
    {
        Schema::table('personeros', function (Blueprint $table) {
            $table->dropForeign(['department_id']);
            $table->dropForeign(['province_id']);
            $table->dropForeign(['district_id']);
            $table->dropForeign(['voting_location_id']);
            $table->dropColumn(['scope', 'department_id', 'province_id', 'district_id', 'voting_location_id', 'attendance']);
        });
    }
};
