<?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
    {
        if (Schema::hasTable('nx_communication_logs')) {
            return;
        }

        Schema::create('nx_communication_logs', function (Blueprint $table) {
            $table->increments('id');
            $table->string('level', 10)->default('info')->comment('info, success, warning, error');
            $table->string('category', 20)->default('system')->comment('connection, worklist, result, error, system');
            $table->string('device_ip', 45)->nullable();
            $table->string('sample_no', 13)->nullable();
            $table->text('message');
            $table->json('context')->nullable();
            $table->timestamps();
            $table->softDeletes();

            $table->index(['created_at']);
            $table->index(['level']);
            $table->index(['category']);
        });
    }

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