<?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('webhooks', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->uuid('uuid')->unique();
            // Optional HMAC signing secret - null means the unguessable URL
            // itself is the only guard, which is fine for plain HTML forms
            // that can't compute a signature (same model Mailchimp/ActiveCampaign use).
            $table->string('secret')->nullable();
            $table->string('default_status')->default('subscribed');
            $table->string('duplicate_handling')->default('update'); // skip|update
            $table->string('success_redirect_url')->nullable();
            $table->boolean('is_active')->default(true);
            $table->unsignedInteger('total_received')->default(0);
            $table->timestamp('last_triggered_at')->nullable();
            $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
            $table->timestamps();
        });
    }

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