<?php

declare(strict_types=1);

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

return new class extends Migration
{
    public function up(): void
    {
        if (Schema::hasTable('{{ table }}')) {
            return;
        }

        Schema::create('{{ table }}', function (Blueprint $table): void {
            $table->id();
            $table->ulid()->unique();
            $table->foreignId('branch_id')->constrained()->cascadeOnUpdate()->restrictOnDelete();

            $table->string('name', 190);

            $table->timestamps();
            $table->softDeletes();
            $table->foreignId('created_by')->nullable()->constrained('users')->nullOnDelete();
            $table->foreignId('updated_by')->nullable()->constrained('users')->nullOnDelete();

            $table->index(['branch_id', 'deleted_at']);
        });
    }

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