<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Modules\HR\Enums\HolidayAllowancesStatus;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('holiday_allowances', function (Blueprint $table) {
            $table->id();

            $table->foreignId('employee_id')
                ->constrained()
                ->cascadeOnDelete();

            $table->foreignId('attendance_id')
                ->nullable()
                ->constrained()
                ->nullOnDelete();

            $table->foreignId('holiday_id')
                ->nullable()
                ->constrained()
                ->nullOnDelete();

            $table->foreignId('payroll_id')
                ->nullable();


            $table->date('allowance_date');

            $table->decimal('amount', 12, 2);

            $table->foreignId('approved_by')
                ->nullable()
                ->constrained('users')
                ->nullOnDelete();

            $table->timestamp('applied_at')->nullable();

            $table->enum('status', HolidayAllowancesStatus::casesAsArray())->default(HolidayAllowancesStatus::PENDING);

            $table->boolean('is_locked')
                ->default(false);

            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('holiday_allowances');
    }
};
