<?php

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

/**
 * Bearer tokens for the VRC staff PWA (hashed). Lives on the VRC project DB.
 */
return new class extends Migration {
    public function up(): void
    {
        if (Schema::hasTable('vrc_staff_tokens')) {
            return;
        }
        Schema::create('vrc_staff_tokens', function (Blueprint $t) {
            $t->bigIncrements('id');
            $t->unsignedInteger('user_id')->index();
            $t->unsignedInteger('business_id')->nullable();
            $t->string('token_hash', 64)->unique();
            $t->string('user_agent', 255)->nullable();
            $t->string('ip', 45)->nullable();
            $t->timestamp('expires_at')->nullable();
            $t->timestamp('last_used_at')->nullable();
            $t->timestamps();
        });
    }

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