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

            $table->foreignId('employee_advance_id')->constrained()->cascadeOnDelete();
            $table->foreignId('paid_by_id')->nullable()->constrained('users')->restrictOnDelete();
            $table->foreignId('cash_transaction_id')->nullable()->unique()->constrained('cash_transactions')->restrictOnDelete();

            $table->unsignedBigInteger('amount');
            $table->string('description', 100)->nullable();
            $table->timestamp('paid_at')->useCurrent();

            $table->timestamp('created_at')->useCurrent();
            $table->timestamp('updated_at')->useCurrent()->useCurrentOnUpdate();
        });
    }

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