<?php

declare(strict_types=1);

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('article_votes', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('article_id')->constrained('knowledge_base_articles')->cascadeOnDelete();
            $table->foreignId('user_id')->nullable()->constrained('users')->cascadeOnDelete();
            $table->boolean('is_helpful');
            $table->string('ip_address', 45);
            $table->timestamps();

            $table->unique(['article_id', 'user_id']);
            $table->index(['article_id', 'ip_address']);
        });
    }

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