<?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('device_tokens', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            // No DB-level FK on tenant_id (integrity comes from BelongsToTenant +
            // TenantScope), matching every other owned table in this app.
            $table->unsignedBigInteger('tenant_id')->nullable()->index();
            // SHA-256 hex digest of the raw token — deterministic and
            // queryable, unlike a bcrypt hash (mirrors Sanctum's own approach).
            $table->string('token_hash')->unique();
            $table->timestamp('expires_at');
            $table->timestamps();
        });
    }

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