<?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
    {
        Schema::create('companies', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('code')->unique();
            $table->unsignedBigInteger('business_type_id')->nullable();
            $table->string('proprietor')->nullable();
            $table->string('email')->unique();
            $table->string('number')->nullable();
            $table->string('nid')->nullable();
            $table->text('address')->nullable();
            $table->string('status')->default('0'); // 0 = pending, 1 = approved
            $table->timestamps();

            $table->foreign('business_type_id')->references('id')->on('business_types')->onDelete('set null');
            $table->index('code');
            $table->index('email');
            $table->index('business_type_id');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('companies');
    }
};
