<?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
    {
        $addAadhaar = ! Schema::hasColumn('user_kyc', 'aadhaar_document_path');
        $addPhoto = ! Schema::hasColumn('user_kyc', 'photo_path');

        if (! $addAadhaar && ! $addPhoto) {
            return;
        }

        Schema::table('user_kyc', function (Blueprint $table) use ($addAadhaar, $addPhoto): void {
            if ($addAadhaar) {
                $table->string('aadhaar_document_path')->nullable()->after('pan_document_path');
            }
            if ($addPhoto) {
                $table->string('photo_path')->nullable()->after('cancelled_cheque_path');
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        $dropAadhaar = Schema::hasColumn('user_kyc', 'aadhaar_document_path');
        $dropPhoto = Schema::hasColumn('user_kyc', 'photo_path');

        if (! $dropAadhaar && ! $dropPhoto) {
            return;
        }

        Schema::table('user_kyc', function (Blueprint $table) use ($dropAadhaar, $dropPhoto): void {
            if ($dropAadhaar) {
                $table->dropColumn('aadhaar_document_path');
            }
            if ($dropPhoto) {
                $table->dropColumn('photo_path');
            }
        });
    }
};
