<?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('penugasan_items', function (Blueprint $table) {
            $table->id('id_penugasan_item');
            $table->unsignedBigInteger('id_penugasan');
            $table->unsignedBigInteger('id_tarif')->nullable();
            
            $table->string('jenis_pekerjaan');
            $table->string('dimensi_pipa')->nullable();
            $table->decimal('jarak_meter', 10, 2)->nullable();
            $table->integer('jumlah_unit')->nullable();
            $table->integer('jumlah_titik')->nullable();
            $table->boolean('pakai_pipa_besi')->nullable();
            $table->string('jenis_pengangkatan')->nullable(); // gate_valve atau meteran_air
            
            $table->decimal('total_nilai_pekerjaan', 15, 2)->default(0);
            $table->timestamps();

            $table->foreign('id_penugasan')->references('id_penugasan')->on('penugasans')->onDelete('cascade');
            $table->foreign('id_tarif')->references('id_tarif')->on('tarif_pekerjaans')->onDelete('set null');
        });
    }

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