<?php

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

return new class extends Migration
{
    public function up()
    {
        Schema::create('rate_alerts', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained('users')->onDelete('cascade');
            $table->string('from_currency', 3);
            $table->string('to_currency', 3);
            $table->decimal('target_rate', 10, 6);
            $table->enum('condition', ['above', 'below', 'equals']);
            $table->boolean('is_active')->default(true);
            $table->timestamp('last_triggered')->nullable();
            $table->enum('notification_method', ['email', 'push', 'sms'])->default('email');
            $table->timestamps();

            $table->index(['user_id', 'is_active']);
            $table->index(['from_currency', 'to_currency']);
            $table->unique(['user_id', 'from_currency', 'to_currency']);
        });
    }

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