<?php

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('checklist_entries', function (Blueprint $table) {
            $table->id();
            $table->foreignId('unit_id')->constrained('units')->cascadeOnDelete();
            $table->foreignId('entered_by')->constrained('users')->cascadeOnDelete();
            $table->date('entry_date');
            $table->time('entry_time');
            $table->enum('condition_status', ['good', 'warning', 'critical'])->default('good');
            $table->tinyInteger('issue_found')->default(0);
            $table->tinyInteger('maintenance_required')->default(0);
            $table->json('custom_fields')->nullable();
            $table->text('notes')->nullable();
            $table->string('image', 255)->nullable();
            $table->foreignId('last_edited_by')->nullable()->constrained('users')->nullOnDelete();
            $table->timestamp('last_edited_at')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('checklist_entries');
    }
};
