<?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('bom_pick_list_employees', function (Blueprint $table) {
            $table->id();
            $table->foreignId('bom_pick_list_id')->constrained('bom_pick_lists')->cascadeOnDelete();
            $table->foreignId('employee_id')->constrained('accounts')->restrictOnDelete(); // employee/worker from accounts table
            $table->boolean('is_checked')->default(false);
            $table->text('notes')->nullable();
            $table->foreignId('assigned_by')->constrained('users')->restrictOnDelete();
            $table->timestamps();

            // Indexes
            $table->index(['bom_pick_list_id', 'employee_id']);
            $table->unique(['bom_pick_list_id', 'employee_id']); // Prevent duplicate assignments
        });
    }

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