<?php

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

return new class extends Migration
{
    /**
     * MariaDB nu suportă partial unique indexes (UNIQUE WHERE deleted_at IS NULL).
     * Drop unique-ul fizic și păstrăm doar index pentru performanță;
     * unicitatea slug-ului e impusă la nivel de validare Filament + provisioner.
     */
    public function up(): void
    {
        Schema::table('companies', function (Blueprint $t) {
            // Drop existing unique (default name companies_slug_unique).
            try { $t->dropUnique('companies_slug_unique'); } catch (\Throwable $e) {}
            $t->index('slug', 'companies_slug_index');
        });
    }

    public function down(): void
    {
        Schema::table('companies', function (Blueprint $t) {
            try { $t->dropIndex('companies_slug_index'); } catch (\Throwable $e) {}
            $t->unique('slug', 'companies_slug_unique');
        });
    }
};
