<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('employee_bonuses', function (Blueprint $table) {
            $table->id();

            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->foreignId('employee_id')->constrained()->cascadeOnDelete();

            $table->string('bonus_type', 50);
            $table->string('title');
            $table->decimal('amount', 14, 2);

            $table->date('bonus_date');
            $table->enum('status', ['unpaid', 'paid'])->default('unpaid');

            $table->timestamp('paid_at')->nullable();

            $table->unsignedBigInteger('user_account_id')->nullable();
            $table->string('payment_method', 50)->nullable();
            $table->string('reference_no')->nullable();
            $table->text('note')->nullable();

            $table->timestamps();

            $table->index(['user_id', 'employee_id']);
            $table->index(['user_id', 'status']);
            $table->index(['user_id', 'bonus_date']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('employee_bonuses');
    }
};