<?php

use Hyperf\Database\Schema\Schema;
use Hyperf\Database\Schema\Blueprint;
use Hyperf\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('cooperative_votes', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('hashkey', 300)->unique();
            $table->bigInteger('resolution_id')->index();
            $table->bigInteger('user_id')->index();
            $table->enum('vote_cast', ['YES', 'NO', 'ABSTAIN'])->default('ABSTAIN');
            $table->bigInteger('created_by')->nullable();
            $table->bigInteger('updated_by')->nullable();
            $table->boolean('is_active')->default(true);
            $table->datetimes();
            
            $table->unique(['resolution_id', 'user_id']); // Ensure one vote per member per resolution
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('cooperative_votes');
    }
};
