<?php

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

/**
 * Per-user "undo send" delay (in seconds). Users pick 5/10/20/30 from
 * Settings → Profile; the compose + reply screens honour this when
 * showing the post-send toast countdown.
 *
 * Default 10 matches the previous hard-coded value so existing users
 * see no behaviour change until they choose a different value.
 *
 * Idempotent — skips if the column already exists (safe to re-run).
 */
return new class extends Migration {
    public function up(): void
    {
        if (!Schema::hasColumn('users', 'undo_send_delay_seconds')) {
            Schema::table('users', function (Blueprint $table) {
                $table->unsignedTinyInteger('undo_send_delay_seconds')->default(10)->after('timezone');
            });
        }
    }

    public function down(): void
    {
        if (Schema::hasColumn('users', 'undo_send_delay_seconds')) {
            Schema::table('users', function (Blueprint $table) {
                $table->dropColumn('undo_send_delay_seconds');
            });
        }
    }
};
