<?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('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->string('mac_address', 17)->nullable()->unique()->comment('MAC地址');
            $table->foreignId('station_id')->nullable()->constrained()->nullOnDelete();
            $table->string('diagram_url', 500)->nullable()->comment('组态界面地址');
            $table->string('scada_data_url', 500)->nullable()->comment('网关数据查询地址');
            $table->string('scada_tags_url', 500)->nullable()->comment('网关点位定义查询地址');
            $table->boolean('voice_wakeup_enabled')->default(false);
            $table->string('voice_wakeup_word', 100)->nullable();
            $table->boolean('is_online')->default(false);
            $table->timestamp('last_online_at')->nullable();
            $table->timestamps();
            $table->softDeletes();

            $table->index('is_online', 'idx_online');
        });
    }

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