<?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_setups', function (Blueprint $table) {
            $table->id();
            $table->foreignId('organisation_id')->constrained()->cascadeOnDelete();

            $table->string('name'); // e.g., "Annual Performance Bonus"
            $table->enum('bonus_type', [
                'performance',
                'sales_bonus',
                'sales_commission',
                'lt_incentive',
                'cash_incentive'
            ])->default('performance');

            // For different calculation types
            $table->enum('calculation_type', ['flat', 'percentage', 'formula'])->default('percentage');
            $table->decimal('flat_amount', 15, 2)->nullable(); // For flat bonuses
            $table->decimal('target_percent', 5, 2)->nullable(); // % of base salary target
            $table->decimal('max_percent', 5, 2)->nullable(); // % max for percentage-based bonuses
            $table->text('formula')->nullable(); // optional formula

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

            $table->boolean('active')->default(true);
            $table->date('effective_start')->nullable();
            $table->date('effective_end')->nullable();

            $table->timestamps();
        });



    }

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