<?php

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('sales_prospects', function (Blueprint $table) {
            $table->id();
            $table->foreignId('manager_id')->constrained('sales_managers')->cascadeOnDelete()->comment('영업한 영업파트너 ID');
            $table->foreignId('sales_manager_id')->nullable()->constrained('sales_managers')->nullOnDelete()->comment('매칭된 매니저 ID');
            $table->string('company_name', 200)->comment('업체명');
            $table->string('representative', 100)->nullable()->comment('대표자명');
            $table->string('business_no', 20)->nullable()->comment('사업자번호');
            $table->string('contact_phone', 20)->nullable()->comment('연락처');
            $table->string('email', 100)->nullable()->comment('이메일');
            $table->string('address', 500)->nullable()->comment('주소');
            $table->enum('status', ['lead', 'prospect', 'negotiation', 'contracted', 'lost'])->default('lead')->comment('상태');
            $table->timestamps();
            $table->softDeletes();

            $table->index('manager_id');
            $table->index('sales_manager_id');
            $table->index('status');
            $table->index('business_no');
        });
    }

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