<?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('appointments', function (Blueprint $table) {
            $table->id();
            $table->foreignId('customer_id')->constrained()->onDelete('cascade');
            $table->foreignId('vehicle_id')->constrained()->onDelete('cascade');
            $table->foreignId('assigned_technician_id')->nullable()->constrained('technicians')->onDelete('set null');
            $table->datetime('scheduled_datetime');
            $table->integer('estimated_duration_minutes');
            $table->enum('appointment_type', ['maintenance', 'repair', 'inspection', 'estimate', 'pickup', 'delivery']);
            $table->text('service_requested');
            $table->text('customer_notes')->nullable();
            $table->text('internal_notes')->nullable();
            $table->enum('status', ['scheduled', 'confirmed', 'in_progress', 'completed', 'cancelled', 'no_show'])->default('scheduled');
            $table->datetime('checked_in_at')->nullable();
            $table->datetime('completed_at')->nullable();
            $table->foreignId('service_order_id')->nullable()->constrained()->onDelete('set null');
            $table->timestamps();
        });
    }

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