<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('features', function (Blueprint $table) {
            $table->id();

            // Producto al que pertenece la feature
            $table->foreignId('product_id')
                ->constrained('products')
                ->cascadeOnUpdate()
                ->cascadeOnDelete();

            // Título de la feature
            $table->string('title');

            // Descripción corta
            $table->text('description')->nullable();

            // Contenido HTML (longText)
            $table->longText('content_html')->nullable();

            // Imagen miniatura (ruta relativa)
            $table->string('thumbnail_image')->nullable();

            // Imagen de cabecera (ruta relativa)
            $table->string('header_image')->nullable();

            // Estado: draft, published, archived
            $table->enum('status', ['draft', 'published', 'archived'])->default('draft');

            // Orden de visualización
            $table->integer('sort_order')->nullable();

            // Usuario que creó la feature
            $table->foreignId('created_by')
                ->nullable()
                ->constrained('users')
                ->nullOnDelete()
                ->cascadeOnUpdate();

            $table->timestamps();

            // Índices
            $table->index(['product_id', 'status']);
            $table->index('sort_order');
        });
    }

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