<?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_component_values', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id');
            $table->unsignedBigInteger('component_definition_id');
            $table->string('value_type', 32)->default('fixed');
            $table->decimal('value', 15, 4)->nullable();
            $table->date('effective_from')->nullable();
            $table->date('effective_to')->nullable();
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users')->cascadeOnDelete();
            $table->foreign('component_definition_id')->references('id')->on('payroll_component_definitions')->cascadeOnDelete();
            $table->index(['user_id', 'component_definition_id']);
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('employee_component_values');
    }
};
