<?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('customers', function (Blueprint $table) {
            $table->id();
            $table->enum('type', ['individual', 'legal'])->default('individual');
            $table->string('first_name')->nullable();
            $table->string('last_name')->nullable();
            $table->string('company_name')->nullable();
            $table->string('national_code')->nullable();   // کد ملی (حقیقی)
            $table->string('national_id')->nullable();      // شناسه ملی (حقوقی)
            $table->string('economic_code')->nullable();
            $table->string('email')->nullable();
            $table->enum('status', ['lead', 'following', 'active', 'inactive'])->default('lead');
            $table->foreignId('assigned_user_id')->nullable()->constrained('users')->nullOnDelete();
            $table->text('description')->nullable();
            $table->timestamps();

            $table->index('status');
            $table->index('assigned_user_id');
        });
    }

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