<?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_settings', function (Blueprint $table) {
            $table->id();
            $table->foreignId('association_id')->unique()->constrained()->cascadeOnDelete();

            // Default rules (JSON)
            $table->json('default_voter_eligibility')->nullable();
            $table->json('default_candidate_eligibility')->nullable();
            $table->json('default_voting_rules')->nullable();

            // Defaults
            $table->string('default_voting_strategy', 30)->default('plurality');
            $table->string('default_voting_method', 20)->default('online');
            $table->string('default_timezone', 60)->default('Africa/Lagos');
            $table->unsignedSmallInteger('default_quorum_percentage')->default(0);
            $table->string('default_tie_breaking_rule', 30)->default('runoff');
            $table->unsignedSmallInteger('default_required_certifiers')->default(1);

            // Nomination settings
            $table->boolean('allow_self_nomination')->default(true);
            $table->boolean('require_endorsements')->default(false);
            $table->unsignedSmallInteger('min_endorsements')->default(0);

            // Verification
            $table->boolean('send_otp_for_voting')->default(false);

            // Notification preferences
            $table->json('notification_preferences')->nullable();

            $table->timestamps();
        });
    }

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