<?php

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

/**
 * Tags a per-solicitor contract as a Redress Scheme annex (Part 1 additional
 * care settings, or Part 2 additional statement pages). Null = an ordinary
 * contract, so every existing row keeps its current behaviour.
 */
return new class extends Migration {
    public function up(): void
    {
        Schema::table('contracts', function (Blueprint $t) {
            if (! Schema::hasColumn('contracts', 'redress_role')) {
                $t->string('redress_role')->nullable()->index();
            }
        });
    }

    public function down(): void
    {
        Schema::table('contracts', function (Blueprint $t) {
            $t->dropIndex(['redress_role']);
            $t->dropColumn('redress_role');
        });
    }
};
