<?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('mailing_bounces', function (Blueprint $table) {
            $table->id();
            $table->string('email')->index();
            $table->string('bounce_type')->nullable(); // hard, soft, complaint
            $table->text('bounce_reason')->nullable();
            $table->foreignId('mailing_id')->nullable()->constrained()->nullOnDelete();
            $table->timestamp('bounced_at');
            $table->boolean('is_suppressed')->default(false);
            $table->timestamps();

            $table->unique(['email', 'mailing_id']);
        });
    }

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