<?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
    {
        if (! Schema::hasTable('customer_quality_metrics')) {
            return;
        }

        Schema::table('customer_quality_metrics', function (Blueprint $table) {
            if (! Schema::hasColumn('customer_quality_metrics', 'is_internal')) {
                $table->boolean('is_internal')->default(false)->index()->after('is_blocked');
            }
            if (! Schema::hasColumn('customer_quality_metrics', 'internal_exclusion_reason')) {
                $table->string('internal_exclusion_reason', 191)->nullable()->after('is_internal');
            }
        });
    }

    public function down(): void
    {
        if (! Schema::hasTable('customer_quality_metrics')) {
            return;
        }
        Schema::table('customer_quality_metrics', function (Blueprint $table) {
            if (Schema::hasColumn('customer_quality_metrics', 'internal_exclusion_reason')) {
                $table->dropColumn('internal_exclusion_reason');
            }
            if (Schema::hasColumn('customer_quality_metrics', 'is_internal')) {
                $table->dropColumn('is_internal');
            }
        });
    }
};
