<?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_sync_logs')) {
            return;
        }
        Schema::table('customer_quality_sync_logs', function (Blueprint $table) {
            if (! Schema::hasColumn('customer_quality_sync_logs', 'skipped_reasons')) {
                $table->json('skipped_reasons')->nullable()->after('skipped_count');
            }
            if (! Schema::hasColumn('customer_quality_sync_logs', 'skipped_rows')) {
                $table->json('skipped_rows')->nullable()->after('skipped_reasons');
            }
        });
    }

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