<?php
// Nowills SQC ERP — B9: drilling operations entry (pattern, holes, meters)
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
    public function up(): void {
        Schema::create('drill_logs', function (Blueprint $table) {
            $table->id();
            $table->string('drill_no', 30)->unique();
            $table->date('drill_date')->index();
            $table->foreignId('quarry_id')->constrained();
            $table->foreignId('bench_id')->nullable()->constrained('pit_benches')->nullOnDelete();
            $table->foreignId('equipment_id')->nullable()->comment('Drill rig')->constrained('equipment')->nullOnDelete();
            $table->string('pattern', 20)->default('staggered'); // staggered, square, single-row
            $table->decimal('burden_m', 8, 2)->default(0);
            $table->decimal('spacing_m', 8, 2)->default(0);
            $table->unsignedInteger('hole_diameter_mm')->default(89);
            $table->unsignedInteger('holes_planned')->default(0);
            $table->unsignedInteger('holes_drilled')->default(0);
            $table->decimal('depth_per_hole_m', 8, 2)->default(0);
            $table->decimal('total_meters', 12, 2)->default(0); // auto: holes × depth
            $table->string('operator_name', 100)->nullable();
            $table->string('status', 20)->default('planned')->index();
            $table->text('remarks')->nullable();
            $table->timestamps();
        });
    }
    public function down(): void {
        Schema::dropIfExists('drill_logs');
    }
};
