<?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('push_device_tokens', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->unsignedBigInteger('user_id')->comment('사용자 ID');
            $table->text('token')->comment('FCM 디바이스 토큰');
            $table->string('platform', 20)->comment('플랫폼: ios, android, web');
            $table->string('device_name')->nullable()->comment('디바이스명');
            $table->string('app_version', 50)->nullable()->comment('앱 버전');
            $table->boolean('is_active')->default(true)->comment('활성화 여부');
            $table->timestamp('last_used_at')->nullable()->comment('마지막 사용 시간');
            $table->timestamps();
            $table->softDeletes();

            // 인덱스
            $table->index(['tenant_id', 'user_id']);
            $table->index(['user_id', 'is_active']);
            $table->index('platform');
        });
    }

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