<?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('corporate_travelers', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('corporate_account_id');
            $table->unsignedBigInteger('user_id');
            $table->string('employee_id', 50)->nullable();
            $table->string('department', 100)->nullable();
            $table->string('job_title', 100)->nullable();
            $table->unsignedBigInteger('manager_id')->nullable();
            $table->string('cost_center', 100)->nullable();
            $table->decimal('spending_limit', 12, 2)->nullable();
            $table->enum('status', ['active', 'inactive', 'on_leave'])
                ->default('active');
            $table->integer('total_trips')->default(0);
            $table->decimal('total_spent', 12, 2)->default(0);
            $table->timestamps();
            
            $table->foreign('corporate_account_id')->references('id')->on('corporate_accounts')->onDelete('cascade');
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('manager_id')->references('id')->on('users')->nullOnDelete();
            $table->index('corporate_account_id');
            $table->index('status');
        });
    }

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