<?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('permanent_employee_punishments', function (Blueprint $table) {
            $table->id();
            $table->foreignId('created_by')
                ->nullable()
                ->constrained('users')
                ->nullOnDelete();
            $table->foreignId('permanent_employee_id')
                ->constrained('permanent_employees')
                ->cascadeOnDelete();
            $table->date('effective_date');
            $table->decimal('amount', 12, 2);
            $table->text('reason');
            $table->timestamps();

            $table->index(
                ['permanent_employee_id', 'effective_date'],
                'perm_emp_punishments_emp_date_idx',
            );
        });
    }

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