<?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_device_connections')) {
            return;
        }

        Schema::create('nx_device_connections', function (Blueprint $table) {
            $table->increments('id');
            $table->string('device_ip', 45)->nullable();
            $table->unsignedSmallInteger('device_port')->nullable();
            $table->enum('comm_type', ['1', '2', '3', 'A', 'B', '4', 'C']);
            $table->enum('status', ['connected', 'disconnected', 'error'])->default('disconnected');
            $table->timestamp('connected_at')->nullable();
            $table->timestamp('disconnected_at')->nullable();
            $table->unsignedInteger('messages_received')->default(0);
            $table->unsignedInteger('results_stored')->default(0);
            $table->timestamps();
        });
    }

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