<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('travel_plans', function (Blueprint $table) {
            $table->id();
            $table->foreignId('employee_id')->constrained('users');
            $table->date('from_date');
            $table->date('to_date');
            $table->string('from_location')->nullable();
            $table->string('to_location')->nullable();
            $table->text('purpose')->nullable();
            $table->decimal('amount')->nullable();
            $table->text('signature')->nullable();
            $table->date('signature_date')->nullable();
            $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->text('approved_remark')->nullable();
            $table->foreignId('rejected_by')->nullable()->constrained('users');
            $table->dateTime('rejected_at')->nullable();
            $table->text('rejected_remark')->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_plans');
    }
};
