<?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_commissions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('employee_id')->constrained('employees')->cascadeOnDelete();
            $table->string('service_key');
            $table->string('commission_type');
            $table->unsignedBigInteger('base_amount');
            $table->unsignedInteger('percentage');
            $table->unsignedBigInteger('commission_amount');
            $table->string('status')->default('pending');
            $table->timestamp('eligible_at');
            $table->timestamps();

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

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