<?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_records', function (Blueprint $table) {
            $table->id();
            $table->foreignId('manager_id')->constrained('sales_managers')->cascadeOnDelete()->comment('담당자 ID');
            $table->foreignId('prospect_id')->nullable()->constrained('sales_prospects')->nullOnDelete()->comment('가망고객 ID');
            $table->date('record_date')->comment('실적 일자');
            $table->string('record_type', 50)->comment('실적 유형');
            $table->decimal('amount', 15, 2)->default(0)->comment('실적 금액');
            $table->decimal('commission', 15, 2)->default(0)->comment('수수료');
            $table->text('description')->nullable()->comment('설명');
            $table->enum('status', ['pending', 'approved', 'rejected', 'paid'])->default('pending')->comment('상태');
            $table->timestamps();
            $table->softDeletes();

            $table->index('manager_id');
            $table->index('prospect_id');
            $table->index('record_date');
            $table->index('status');
        });
    }

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