<?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->string('first_name');
            $table->string('last_name');

            $table->string('email')->unique();
            $table->string('phone', 20)->unique();

            $table->timestamp('email_verified_at')->nullable();
            $table->string('email_verification_code', 10)->nullable();
            $table->timestamp('email_verification_expires_at')->nullable();

            $table->string('password');
            $table->rememberToken();

            $table->string('password_reset_token')->nullable();
            $table->timestamp('password_reset_expires_at')->nullable();

            $table->date('birth_date')->nullable();
            $table->enum('gender', ['male', 'female', 'other'])->nullable();
            $table->string('avatar')->nullable();

            $table->boolean('is_active')->default(true);
            $table->boolean('accepts_marketing')->default(true);

            $table->integer('total_orders')->default(0);
            $table->decimal('total_spent', 10, 2)->default(0.00);
            $table->timestamp('last_order_at')->nullable();
            $table->timestamp('last_login_at')->nullable();
            $table->timestamp('customer_since')->useCurrent();

            $table->text('notes')->nullable();

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

            $table->index('is_active');
            $table->index('email_verified_at');
        });
    }

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