<?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('notification_log', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->string('channel')->comment('email | push | whatsapp | sms');
            $table->string('trigger_type')->comment('price_threshold | score_change | scheduled_morning | scheduled_evening');
            $table->string('fuel_type');
            $table->decimal('price', 8, 3)->nullable();
            $table->boolean('sent');
            $table->string('missed_reason')->nullable()->comment('daily_limit | tier_restricted | user_disabled');
            $table->timestamp('created_at')->useCurrent();

            $table->index(['user_id', 'channel', 'created_at']);
            $table->index(['user_id', 'sent', 'created_at']);
        });
    }

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