<?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
    {
        Schema::create('terminals', function (Blueprint $table) {
            $table->id();
            $table->string('name')->comment('终端名称');
            $table->string('code', 100)->unique()->comment('终端编码');
            $table->string('ip_address', 45)->nullable()->comment('IP地址');
            $table->unsignedBigInteger('station_id')->nullable()->comment('线站ID');
            $table->string('diagram_url', 500)->nullable()->comment('组态图URL');
            $table->json('display_config')->nullable()->comment('显示配置');
            $table->boolean('is_online')->default(false)->comment('在线状态');
            $table->timestamp('last_online_at')->nullable()->comment('最后在线时间');
            $table->timestamps();
            $table->softDeletes();

            // 添加索引
            $table->index('station_id', 'idx_station');
            $table->index('is_online', 'idx_online');
        });
    }

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