<?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_prospect_products', function (Blueprint $table) {
            $table->id();
            $table->foreignId('prospect_id')->constrained('sales_prospects')->cascadeOnDelete();
            $table->string('product_name', 200)->comment('상품명');
            $table->decimal('contract_amount', 15, 2)->default(0)->comment('계약금액');
            $table->decimal('subscription_fee', 15, 2)->default(0)->comment('구독료');
            $table->decimal('commission_rate', 5, 2)->default(20)->comment('수수료율');
            $table->decimal('commission_amount', 15, 2)->default(0)->comment('수수료');
            $table->date('contract_date')->nullable()->comment('계약일');
            $table->boolean('join_approved')->default(false)->comment('가입 승인 여부');
            $table->boolean('payment_approved')->default(false)->comment('결제 승인 여부');
            $table->decimal('payout_rate', 5, 2)->default(0)->comment('지급율');
            $table->decimal('payout_amount', 15, 2)->default(0)->comment('지급금액');
            $table->json('sub_models')->nullable()->comment('선택모델 목록');
            $table->timestamps();
            $table->softDeletes();

            $table->index('prospect_id');
            $table->index('contract_date');
        });
    }

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