<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('contact_messages', function (Blueprint $t) {
            if (!Schema::hasColumn('contact_messages', 'classification')) {
                $t->string('classification', 32)->nullable()->after('from_email');
            }
            if (!Schema::hasColumn('contact_messages', 'classification_status')) {
                $t->string('classification_status', 16)->nullable()->after('classification');
            }
            if (!Schema::hasColumn('contact_messages', 'classification_confidence')) {
                $t->string('classification_confidence', 16)->nullable()->after('classification_status');
            }
            if (!Schema::hasColumn('contact_messages', 'classification_notes')) {
                $t->text('classification_notes')->nullable()->after('classification_confidence');
            }

            $t->index(['solicitor_id', 'classification', 'classification_status'], 'cm_solicitor_class_status_idx');
        });
    }

    public function down(): void
    {
        Schema::table('contact_messages', function (Blueprint $t) {
            $t->dropIndex('cm_solicitor_class_status_idx');
            $t->dropColumn([
                'classification',
                'classification_status',
                'classification_confidence',
                'classification_notes',
            ]);
        });
    }
};
