<?php

// database/migrations/xxxx_xx_xx_create_payroll_deductions_table.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('deductions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('branch_id')->nullable();
            $table->string('code')->unique();
            $table->string('name');
            $table->string('payslip_label');
            $table->text('description')->nullable();

            $table->enum('calculation_type', ['FIXED', 'FORMULA', 'BOTH']);
            $table->decimal('fixed_amount', 12, 2)->nullable();
            $table->text('formula_expression')->nullable();

            $table->boolean('is_epf_applicable')->default(false);
            $table->boolean('is_etf_applicable')->default(false);
            $table->boolean('is_gross_applicable')->default(false);
            $table->boolean('is_net_applicable')->default(true);

            $table->unsignedSmallInteger('sort_order')->default(0);
            $table->date('effective_from')->nullable();
            $table->date('effective_to')->nullable();

            $table->boolean('status')->default(true);
            $table->timestamps();
        });
    }

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