<?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('job_cards', function (Blueprint $table) {
            $table->foreignId('assigned_technician_id')->nullable()->after('service_advisor_id')->constrained('users')->onDelete('set null');
            $table->text('assignment_notes')->nullable()->after('notes');
            $table->timestamp('assigned_at')->nullable()->after('assignment_notes');
            $table->timestamp('diagnosis_started_at')->nullable()->after('assigned_at');
            $table->timestamp('diagnosis_completed_at')->nullable()->after('diagnosis_started_at');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('job_cards', function (Blueprint $table) {
            $table->dropForeign(['assigned_technician_id']);
            $table->dropColumn([
                'assigned_technician_id',
                'assignment_notes',
                'assigned_at',
                'diagnosis_started_at',
                'diagnosis_completed_at',
            ]);
        });
    }
};
