<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Modules\Travel\Http\Enums\ModeOfTransportationEnum;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('travel_expenses', function (Blueprint $table) {
            $table->id();
            $table->foreignId('employee_id')->constrained('users');
            $table->foreignId('travel_plan_id')->constrained();
            $table->date('date')->nullable();
            $table->enum('mode_of_transportation', array_map(fn(ModeOfTransportationEnum $mode) => $mode->value, ModeOfTransportationEnum::cases()))->nullable();
            $table->decimal('total_amount')->nullable()->default(0);
            $table->decimal('request_amount')->nullable()->default(0);
            $table->decimal('approval_amount')->nullable()->default(0);
            $table->foreignId('status_id')->index('status_id')->default(2)->constrained('statuses')->comment('2 = Pending, 5 = Approved, 6 = Rejected');
            $table->foreignId('approved_by')->nullable()->constrained('users');
            $table->dateTime('approved_at')->nullable();
            $table->unsignedTinyInteger('rating_of_travel_experience')->nullable();

            $table->foreignId('created_by')->nullable()->constrained('users');
            $table->foreignId('updated_by')->nullable()->constrained('users');

            $table->foreignId('company_id')->nullable()->default(1);
            $table->foreignId('branch_id')->nullable()->default(1);
            
            $table->timestamps();
        });
    }

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