<?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_notification_settings', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->unsignedBigInteger('user_id')->comment('사용자 ID');
            $table->string('notification_type', 50)->comment('알림 유형: deposit, withdrawal, order, approval 등');
            $table->boolean('is_enabled')->default(true)->comment('알림 활성화 여부');
            $table->string('sound', 100)->default('default')->comment('알림음 파일명');
            $table->boolean('vibrate')->default(true)->comment('진동 여부');
            $table->boolean('show_preview')->default(true)->comment('미리보기 표시 여부');
            $table->timestamps();

            // 복합 유니크 키
            $table->unique(['tenant_id', 'user_id', 'notification_type'], 'push_settings_unique');

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

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