<?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('election_positions', function (Blueprint $table) {
            $table->id();
            $table->uuid('uuid')->unique();
            $table->foreignId('election_id')->constrained('elections')->cascadeOnDelete();
            $table->foreignId('association_id')->constrained()->cascadeOnDelete();
            $table->string('title');
            $table->text('description')->nullable();
            $table->unsignedSmallInteger('available_seats')->default(1);
            $table->unsignedSmallInteger('max_candidates_per_voter')->default(1);
            $table->unsignedSmallInteger('display_order')->default(0);
            $table->boolean('is_active')->default(true);
            $table->string('voting_strategy_override', 30)->nullable();
            $table->json('metadata')->nullable();
            $table->timestamps();

            $table->index(['election_id', 'display_order']);
        });
    }

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