<?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('technician_consumables', function (Blueprint $table) {
            $table->id();

            $table->unsignedBigInteger('user_id');

            $table->string('barcode_id')->unique();
            $table->unsignedBigInteger('inventory_item_id')->nullable();

            $table->string('material_name');
            $table->string('unit')->default('meter');

            $table->decimal('qty_received', 10, 2)->default(0);
            $table->decimal('qty_used', 10, 2)->default(0);
            $table->decimal('qty_remaining', 10, 2)->default(0);

            $table->dateTime('assigned_at');
            $table->unsignedBigInteger('assigned_by')->nullable();

            $table->timestamps();

            $table->index('user_id');
            $table->index('barcode_id');
        });
    }

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