<?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) {
            // Workflow enhancement fields
            $table->foreignId('delivered_by_id')->nullable()->constrained('users');
            $table->text('delivery_notes')->nullable();
            $table->timestamp('archived_at')->nullable();
            $table->json('incoming_inspection_data')->nullable();
            $table->json('outgoing_inspection_data')->nullable();
            $table->text('quality_alerts')->nullable();
            
            // Add indexes for performance
            $table->index(['status', 'branch_code']);
            $table->index(['archived_at']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('job_cards', function (Blueprint $table) {
            $table->dropForeign(['delivered_by_id']);
            $table->dropColumn([
                'delivered_by_id',
                'delivery_notes',
                'archived_at',
                'incoming_inspection_data',
                'outgoing_inspection_data',
                'quality_alerts'
            ]);
            $table->dropIndex(['status', 'branch_code']);
            $table->dropIndex(['archived_at']);
        });
    }
};
