<?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('seats', function (Blueprint $table) {
            $table->engine = 'InnoDB';

            $table->id();

            $table->foreignId('division_id')->nullable()->constrained('divisions')->nullOnDelete();
            $table->foreignId('district_id')->nullable()->constrained('districts')->nullOnDelete();
            $table->foreignId('upazila_id')->nullable()->constrained('upazilas')->nullOnDelete();
            $table->foreignId('city_id')->nullable()->constrained('cities')->nullOnDelete();

            $table->string('name_bn', 150);
            $table->string('name_en', 150)->nullable();
            $table->string('seat_code', 60)->nullable();     
            $table->string('seat_type', 60);                

            $table->unsignedInteger('male_voters')->default(0);
            $table->unsignedInteger('female_voters')->default(0);
            $table->unsignedInteger('other_voters')->default(0);
            $table->unsignedInteger('total_voters')->default(0);

            $table->text('description')->nullable();
            $table->enum('status', ['active','inactive'])->default('active');

            $table->timestamps();

            $table->index(['division_id', 'status']);
            $table->index(['seat_type', 'status']);
            $table->index(['seat_code']);
        });
    }

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