<?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('lead_sales', function (Blueprint $table) {
            $table->id();
            $table->foreignId('lead_id')->constrained('leads')->cascadeOnDelete();
            $table->foreignId('product_id')->constrained('products')->cascadeOnDelete();
            $table->foreignId('created_by')->constrained('users')->cascadeOnDelete();
            $table->foreignId('assigned_to')->nullable()->constrained('users')->cascadeOnDelete();
            $table->foreignId('sale_by')->constrained('users')->cascadeOnDelete();
            $table->dateTime('sale_date');
            $table->decimal('price', 20, 4)->default(0);
            $table->decimal('quantity', 20, 4)->default(0);
            $table->decimal('total', 20, 4)->default(0);
            $table->foreignId('payment_type_id')->constrained('payment_types')->cascadeOnDelete();
            $table->string('remarks')->nullable();
            $table->decimal('incentive', 20, 4)->default(0);
            $table->unsignedTinyInteger('is_deleted')->default(0);
            $table->timestamps();
            $table->softDeletes();
        });
    }

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