<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('vendors', function (Blueprint $table) {
            $table->text('vtpass_api_key')->nullable()->after('secret_encrypted');
            $table->text('vtpass_public_key')->nullable()->after('vtpass_api_key');
            $table->text('vtpass_secret_key')->nullable()->after('vtpass_public_key');
        });

        if (DB::getDriverName() === 'mysql') {
            DB::statement("ALTER TABLE `vendors` MODIFY `type` ENUM('msorg','smeplug','vtpass') NOT NULL");
        }
    }

    public function down(): void
    {
        if (DB::getDriverName() === 'mysql') {
            DB::statement("ALTER TABLE `vendors` MODIFY `type` ENUM('msorg','smeplug') NOT NULL");
        }

        Schema::table('vendors', function (Blueprint $table) {
            $table->dropColumn(['vtpass_api_key', 'vtpass_public_key', 'vtpass_secret_key']);
        });
    }
};
