<?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_structures', 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->boolean('is_current')->default(true);

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

            $table->timestamps();

            $table->index(['user_id', 'employee_id']);
            $table->index(['user_id', 'salary_type']);
            $table->index(['employee_id', 'is_current']);
        });
    }

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