<?php

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

/**
 * Why a customer left.
 *
 * The cancellation recorded WHEN and nothing else, so the one thing worth
 * knowing about a departure — whether it was the price, a missing feature, or a
 * competitor — existed only in whatever the customer happened to write to
 * support afterwards, which most do not.
 *
 * On the contract rather than on the instance: a contract is what is cancelled,
 * and it is where the withdrawal is already recorded (withdrawal_channel and the
 * rest). The reason is a fixed key, the note is what they typed.
 */
return new class extends Migration
{
    public function up(): void
    {
        Schema::table('subscriptions', function (Blueprint $table) {
            $table->string('cancel_reason', 32)->nullable()->after('cancel_requested_at');
            $table->text('cancel_reason_note')->nullable()->after('cancel_reason');
        });
    }

    public function down(): void
    {
        Schema::table('subscriptions', function (Blueprint $table) {
            $table->dropColumn(['cancel_reason', 'cancel_reason_note']);
        });
    }
};
