<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * MNG → DEV 자동 로그인용 One-Time Token 테이블
     */
    public function up(): void
    {
        Schema::create('login_tokens', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('user_id')->comment('사용자 ID');
            $table->string('token', 64)->unique()->comment('One-Time Token (64자)');
            $table->timestamp('expires_at')->comment('만료 시간');
            $table->timestamps();

            // 인덱스
            $table->index('token');
            $table->index('expires_at');

            // 외래키 (users 테이블과 연결)
            $table->foreign('user_id')
                ->references('id')
                ->on('users')
                ->cascadeOnDelete();
        });
    }

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