<?php

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

/**
 * Whether the person on the other side is a consumer or a business.
 *
 * It was nowhere, and it decides things that are not ours to decide: the
 * fourteen-day right of withdrawal is a consumer's and only a consumer's, the
 * invoice is worded differently for each, and reverse charge is a business rule.
 * All three were being answered from `vat_id`, which cannot answer them — a
 * business without a VAT number is an ordinary small business, and a consumer
 * with one does not exist. A field that is empty for half the businesses we sell
 * to is not the same question.
 *
 * Nullable, and deliberately so. NULL means nobody has ever been asked, which is
 * a different statement from either answer and must not be dressed up as one.
 * Every reader of this column treats NULL as the MORE PROTECTIVE case — the
 * customer keeps the withdrawal right — because getting that wrong costs a
 * customer a statutory right, while getting it wrong the other way costs us a
 * refund we did not strictly owe.
 *
 * A string rather than a boolean: `is_business = false` reads as "we asked and
 * they said no", and there would be no way left to say "we never asked".
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('customers', function (Blueprint $table) {
            // 'consumer' | 'business' | NULL (never recorded).
            $table->string('customer_type', 16)->nullable()->after('email');
        });
    }

    public function down(): void
    {
        Schema::table('customers', function (Blueprint $table) {
            $table->dropColumn('customer_type');
        });
    }
};
