<?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('bonus_payouts', function (Blueprint $table) {
            $table->id();

            $table->foreignId('bonus_setup_id')->constrained()->cascadeOnDelete();
            $table->foreignId('employee_id')->constrained()->cascadeOnDelete();
            $table->foreignId('appraisal_review_id')->nullable()->constrained()->nullOnDelete();

            $table->decimal('target_amount', 12, 2)->nullable();
            $table->decimal('payout_amount', 12, 2)->nullable();
            $table->decimal('multiplier', 5, 2)->nullable(); // 1.2x for high performer, etc.
            $table->decimal('performance_score', 5, 2)->nullable();

            $table->date('payout_date')->nullable();
            $table->enum('status', ['pending', 'approved', 'paid'])->default('pending');

            $table->text('notes')->nullable();

            $table->timestamps();
        });


    }

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