<?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('artigos', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->foreignId('departamento_id')->constrained('departamentos')->cascadeOnDelete();
            $table->foreignId('categoria_id')->constrained('categorias')->cascadeOnDelete();
            $table->string('titulo');
            $table->string('slug')->unique();
            $table->longText('conteudo');
            $table->enum('status', ['rascunho', 'publicado'])->default('rascunho');
            $table->boolean('restrito')->default(false);
            $table->timestamps();
            $table->softDeletes();

            $table->index(['status', 'departamento_id', 'categoria_id']);
        });
    }

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