<?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('automations', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->foreignUuid('user_id')->constrained()->cascadeOnDelete();

            $table->string('type');     // event_reminder | daily_agenda | weekly_overview | event_followup | birthday_reminder | no_activity_reminder
            $table->string('name');

            $table->boolean('active')->default(true);
            $table->json('config')->nullable();

            $table->timestamp('last_run_at')->nullable();
            $table->timestamps();

            $table->unique(['user_id', 'type']);
        });
    }

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