<?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->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->string('customer_code')->unique(); // MS-CUST-1001
            $table->string('full_name');
            $table->string('phone')->index();
            $table->string('alternate_phone')->nullable();
            $table->string('email')->nullable();
            $table->text('address')->nullable();
            $table->string('city')->default('Dhaka');
            $table->string('district')->default('Dhaka');
            $table->string('nid_or_passport')->nullable();
            $table->enum('preferred_contact', ['whatsapp', 'call', 'email'])->default('whatsapp');
            $table->unsignedInteger('total_bids')->default(0);
            $table->unsignedInteger('active_bids')->default(0);
            $table->unsignedInteger('won_bids')->default(0);
            $table->unsignedInteger('lost_bids')->default(0);
            $table->unsignedInteger('total_orders')->default(0);
            $table->decimal('total_spent_bdt', 14, 2)->default(0);
            $table->enum('status', ['active', 'verified', 'suspended'])->default('active');
            $table->text('internal_notes')->nullable();
            $table->timestamps();
        });
    }

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