<?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('salaries', function (Blueprint $table) {
            $table->id();
            $table->foreignId('employee_id')->constrained()->onDelete('cascade');
            $table->string('period'); // Format: YYYY-MM (contoh: 2026-02)
            $table->decimal('base_salary', 12, 2)->default(0); // Gaji pokok
            $table->decimal('allowance', 12, 2)->default(0); // Tunjangan
            $table->decimal('overtime', 12, 2)->default(0); // Lembur
            $table->decimal('bonus', 12, 2)->default(0); // Bonus
            $table->decimal('deduction', 12, 2)->default(0); // Potongan
            $table->decimal('total', 12, 2)->default(0); // Total gaji
            $table->text('notes')->nullable();
            $table->enum('status', ['draft', 'paid'])->default('draft');
            $table->date('paid_at')->nullable();
            $table->timestamps();

            $table->unique(['employee_id', 'period']);
        });
    }

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