<?php

use App\Enums\EntityStatus;
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('customer_references', function (Blueprint $table) {
            $table->id();
            $table->string('name')->nullable();
            $table->string('relationship')->nullable();
            $table->string('phone')->nullable();
            $table->string('email')->nullable();
            $table->string('company')->nullable();
            $table->string('position')->nullable();
            $table->text('comments')->nullable();
            $table->string('code')->nullable();
            $table->boolean('is_influencer')->default(false);

            //Nota: esta relacion esta en la tabla de customers
            //Nota: esta variable trata de si otro clientees la referencia
            // $table->unsignedBigInteger('referred_by_customer_id')->nullable();
            // $table->foreign('referred_by_customer_id')->references('id')->on('customers')->onDelete('cascade');

            $table->enum('entity_status',[EntityStatus::ACTIVE->value, EntityStatus::INACTIVE->value])->default(EntityStatus::ACTIVE->value);
            $table->timestamps();

            $table->unsignedBigInteger('created_by')->nullable();
            $table->unsignedBigInteger('updated_by')->nullable();
            $table->unsignedBigInteger('deleted_by')->nullable();
            $table->foreign('created_by')->references('id')->on('users');
            $table->foreign('updated_by')->references('id')->on('users');
            $table->foreign('deleted_by')->references('id')->on('users');
            $table->softDeletes();
        });
    }

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