<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * Recurring email occurrences are now materialized as real child
     * `campaigns` rows (linked via `parent_id`) instead of lightweight log
     * entries, so this table is superseded.
     */
    public function up(): void
    {
        Schema::dropIfExists('recurring_send_logs');
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::create('recurring_send_logs', function (Blueprint $table) {
            $table->id();
            $table->foreignId('campaign_id')->constrained('campaigns')->cascadeOnDelete();
            $table->timestamp('run_at');
            $table->unsignedInteger('recipients_count')->default(0);
            $table->unsignedInteger('emails_sent')->default(0);
            $table->unsignedInteger('emails_failed')->default(0);
            $table->string('status', 20)->default('sent');
            $table->timestamps();
        });
    }
};
