<?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('contacts', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
            $table->string('hash', 64)->nullable()->unique();
            $table->string('contact_owner')->nullable();
            $table->unsignedBigInteger('company_id')->nullable();
            $table->string('prefix', 20)->nullable();
            $table->string('first_name')->nullable();
            $table->string('last_name')->nullable();
            $table->string('email')->unique();
            $table->string('timezone', 60)->nullable();
            $table->string('address_line_1')->nullable();
            $table->string('address_line_2')->nullable();
            $table->string('postal_code', 20)->nullable();
            $table->string('city', 100)->nullable();
            $table->string('state', 100)->nullable();
            $table->string('country', 100)->nullable();
            $table->string('ip', 45)->nullable();
            $table->decimal('latitude', 10, 8)->nullable();
            $table->decimal('longitude', 11, 8)->nullable();
            $table->unsignedInteger('total_points')->default(0);
            $table->unsignedInteger('life_time_value')->default(0);
            $table->string('phone', 30)->nullable();
            $table->string('status', 50)->default('subscribed');
            $table->string('contact_type', 50)->default('lead');
            $table->string('source', 50)->nullable();
            $table->string('avatar', 192)->nullable();
            $table->date('date_of_birth')->nullable();
            $table->timestamp('last_activity')->nullable();
            $table->timestamps();
        });
    }

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