<?php

use App\Domains\Catalog\Enums\FeaturedGroupSource;
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::table('featured_groups', function (Blueprint $table): void {
            $table->enum('source_type', FeaturedGroupSource::values())
                ->default(FeaturedGroupSource::Manual->value)
                ->after('tenant_code');
            $table->foreignId('category_id')
                ->nullable()
                ->after('source_type')
                ->constrained('categorias')
                ->nullOnDelete();
        });
    }

    public function down(): void
    {
        Schema::table('featured_groups', function (Blueprint $table): void {
            $table->dropConstrainedForeignId('category_id');
            $table->dropColumn('source_type');
        });
    }
};
