<?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
    {
        if (Schema::hasTable('featured_products')) {
            Schema::rename('featured_products', 'featured_variants');
        }

        if (Schema::hasColumn('featured_variants', 'product_id')) {
            Schema::table('featured_variants', function (Blueprint $table) {
                $table->renameColumn('product_id', 'product_variant_id');
            });
        }

        Schema::table('featured_variants', function (Blueprint $table) {
            $table->foreign('product_variant_id')->references('id')->on('productos_variantes')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('featured_variants', function (Blueprint $table) {
            //
        });
    }
};
