<?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('customers')) {
            return;
        }

        Schema::table('customers', function (Blueprint $table) {
            if (! Schema::hasColumn('customers', 'contract_path')) {
                $table->string('contract_path')->nullable()->after('business_link');
            }
            if (! Schema::hasColumn('customers', 'contract_original_name')) {
                $table->string('contract_original_name')->nullable()->after('contract_path');
            }
            if (! Schema::hasColumn('customers', 'contract_mime')) {
                $table->string('contract_mime')->nullable()->after('contract_original_name');
            }
        });
    }

    public function down(): void
    {
        if (! Schema::hasTable('customers')) {
            return;
        }

        Schema::table('customers', function (Blueprint $table) {
            if (Schema::hasColumn('customers', 'contract_mime')) {
                $table->dropColumn('contract_mime');
            }
            if (Schema::hasColumn('customers', 'contract_original_name')) {
                $table->dropColumn('contract_original_name');
            }
            if (Schema::hasColumn('customers', 'contract_path')) {
                $table->dropColumn('contract_path');
            }
        });
    }
};
