<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('business_trips', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->foreignId('company_id')->constrained()->cascadeOnDelete();
            $table->string('title')->nullable();
            $table->text('description')->nullable();

            // Tujuan
            $table->string('destination_city');
            $table->string('destination_province');

            // Periode
            $table->date('start_date');
            $table->date('end_date');

            // Status perjalanan (sederhana: ongoing atau completed)
            $table->enum('status', ['ongoing', 'completed'])->default('ongoing');

            // Lokasi rumah user (copy dari user untuk referensi)
            $table->decimal('home_latitude', 10, 8)->nullable();
            $table->decimal('home_longitude', 11, 8)->nullable();

            $table->timestamps();

            $table->index(['user_id', 'start_date', 'end_date']);
            $table->index(['company_id', 'status']);
        });
    }

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