<?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('payroll_components', function (Blueprint $table) {
            $table->id();
            $table->string('code', 20)->unique();
            $table->string('name', 100)->comment('Contoh: BPJS Ketenagakerjaan, PPh 21, Tunjangan Jabatan');
            $table->enum('type', ['earning', 'deduction']);
            $table->bigInteger('account_id')->unsigned()->nullable()->comment('Mapping langsung ke Chart of Accounts');
            $table->boolean('is_active')->default(true);
            $table->timestamps();

            $table->foreign('account_id')->references('id')->on('accounts')->onDelete('set null');
        });
    }

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