<?php

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::create('branches', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('code', 30)->unique();
            $table->string('phone', 30)->nullable();
            $table->string('email')->nullable();
            $table->string('principal_name')->nullable();
            $table->text('address')->nullable();
            $table->string('city')->nullable();
            $table->string('logo')->nullable();
            $table->boolean('is_active')->default(true)->index();

            // Audit columns added without the macro to avoid a self/users FK
            // ordering problem during the very first migration batch.
            $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();

            $table->timestamps();
            $table->softDeletes();
        });
    }

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