<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('notification_settings', function (Blueprint $table) {
            $table->id();
            $table->foreignId('tenant_id')->constrained()->cascadeOnDelete()->comment('테넌트 ID');
            $table->foreignId('user_id')->constrained()->cascadeOnDelete()->comment('사용자 ID');

            // 알림 유형별 채널 설정
            $table->string('notification_type', 50)->comment('알림 유형 (approval, order, deposit, withdrawal, notice, system 등)');

            // 채널별 활성화 여부
            $table->boolean('push_enabled')->default(true)->comment('푸시 알림 활성화');
            $table->boolean('email_enabled')->default(true)->comment('이메일 알림 활성화');
            $table->boolean('sms_enabled')->default(false)->comment('SMS 알림 활성화');
            $table->boolean('in_app_enabled')->default(true)->comment('인앱 알림 활성화');
            $table->boolean('kakao_enabled')->default(false)->comment('카카오 알림톡 활성화');

            // 추가 설정
            $table->json('settings')->nullable()->comment('추가 설정 (우선순위, 알림 시간대 등)');

            $table->timestamps();

            // 복합 유니크 인덱스
            $table->unique(['tenant_id', 'user_id', 'notification_type'], 'notification_settings_unique');
            $table->index(['user_id', 'notification_type']);
        });
    }

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