<?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_overtimes', function (Blueprint $table) {
            $table->id();
            $table->foreignId('employee_id')->constrained('employees')->onDelete('cascade');
            $table->integer('year');
            $table->integer('month');
            $table->decimal('ot_hours',  8, 2)->default(0);   // total OT hours that month
            /*
             * ot_amount is computed on save:
             *   hourly_rate = basic_salary / (working_days × daily_hours)
             *   ot_amount   = hourly_rate × ot_hours × ot_multiplier
             * We store the computed amount so payslips stay stable even if salary changes.
             */
            $table->decimal('ot_amount', 12, 2)->default(0);
            $table->decimal('ot_multiplier', 4, 2)->default(1.50); // 1.5× standard
            $table->text('notes')->nullable();
            $table->timestamps();

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

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