<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up()
    {
        if (!Schema::hasTable('ss_devices')) {
            Schema::create('ss_devices', function (Blueprint $table) {
                $table->bigIncrements('id');
                $table->unsignedInteger('business_id')->nullable()->index();
                $table->string('name', 191)->nullable();
                $table->string('fingerprint_hash', 191)->index();
                $table->string('ip_cidr', 64)->nullable();
                $table->boolean('approved')->default(false);
                $table->string('last_ip', 64)->nullable();
                $table->string('last_user_agent', 255)->nullable();
                $table->timestamp('last_seen_at')->nullable();
                $table->unsignedInteger('created_by')->nullable();
                $table->timestamps();
            });
        }
    }

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