<?php

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

return new class extends Migration
{
    /**
     * System-recorded acceptances (cron, admin manual, tests without HTTP context)
     * have no real IP/UA. Better to store NULL ("no HTTP context") than the
     * '0.0.0.0' sentinel which is itself a valid IPv4 address.
     */
    public function up(): void
    {
        Schema::table('client_contract_acceptances', function (Blueprint $table) {
            $table->string('ip_address', 45)->nullable()->change();
            $table->text('user_agent')->nullable()->change();
        });
    }

    public function down(): void
    {
        // Note: rollback fails if any acceptance row has NULL ip/ua.
        Schema::table('client_contract_acceptances', function (Blueprint $table) {
            $table->string('ip_address', 45)->nullable(false)->change();
            $table->text('user_agent')->nullable(false)->change();
        });
    }
};
