<?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('employee_salary_histories', function (Blueprint $table) {
            $table->id();

            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->foreignId('employee_id')->constrained()->onDelete('cascade');

            $table->enum('salary_type', ['monthly', 'daily_roz']);

            $table->decimal('monthly_salary', 14, 2)->default(0);
            $table->decimal('per_roz_rate', 14, 2)->default(0);

            $table->decimal('overtime_rate', 12, 2)->default(0);

            $table->date('effective_from');
            $table->date('effective_to')->nullable();

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

            $table->timestamps();

            $table->index(['user_id', 'employee_id']);
            $table->index(['employee_id', 'effective_from']);
            $table->index(['employee_id', 'effective_to']);
        });
    }

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