<?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::table('vehicle_inspections', function (Blueprint $table) {
            // Add job_card_id column to link inspections to job cards
            $table->unsignedBigInteger('job_card_id')->nullable()->after('id');
            
            // Add inspection_type column to distinguish between incoming/outgoing inspections
            $table->enum('inspection_type', ['incoming', 'outgoing'])->default('incoming')->after('job_card_id');
            
            // Add foreign key constraint
            $table->foreign('job_card_id')->references('id')->on('job_cards')->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('vehicle_inspections', function (Blueprint $table) {
            // Drop foreign key constraint first
            $table->dropForeign(['job_card_id']);
            
            // Drop the columns
            $table->dropColumn(['job_card_id', 'inspection_type']);
        });
    }
};
