<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        // 테이블이 존재하지 않으면 건너뛰기
        if (!Schema::hasTable('sales_consultations')) {
            return;
        }

        // 컬럼이 이미 존재하면 건너뛰기
        if (Schema::hasColumn('sales_consultations', 'gcs_uri')) {
            return;
        }

        Schema::table('sales_consultations', function (Blueprint $table) {
            $table->string('gcs_uri', 500)->nullable()->after('duration')
                ->comment('Google Cloud Storage URI (본사 연구용 백업)');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        if (!Schema::hasTable('sales_consultations')) {
            return;
        }

        if (!Schema::hasColumn('sales_consultations', 'gcs_uri')) {
            return;
        }

        Schema::table('sales_consultations', function (Blueprint $table) {
            $table->dropColumn('gcs_uri');
        });
    }
};
