<?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
    {
        if (!Schema::hasTable('work_records')) {
            Schema::create('work_records', function (Blueprint $table) {
                $table->id();
                $table->foreignId('equipment_id')->constrained()->onDelete('cascade');
                $table->string('operator_name')->nullable();
                $table->dateTime('start_time')->nullable();
                $table->dateTime('end_time')->nullable();
                $table->decimal('duration', 10, 2)->default(0); // in hours or days
                $table->string('duration_unit')->default('hour'); // hour, day
                $table->decimal('base_cost', 10, 2)->default(0);
                $table->decimal('total_expenses', 10, 2)->default(0);
                $table->decimal('grand_total', 12, 2)->default(0);
                $table->string('status')->default('completed'); // active, completed
                $table->timestamps();
            });
        }
    }

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