<?php

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

return new class extends Migration {
    public function up(): void
    {
        // Make sure columns exist (create if missing) and force ASCII + <=191 chars
        // Using raw statements avoids "change()" limitations across MySQL variants.
        DB::statement("
            ALTER TABLE deposits
            MODIFY stripe_payment_intent VARCHAR(191)
                CHARACTER SET ascii COLLATE ascii_general_ci NULL
        ");
        DB::statement("
            ALTER TABLE deposits
            MODIFY stripe_charge VARCHAR(191)
                CHARACTER SET ascii COLLATE ascii_general_ci NULL
        ");

        // Now the composite index fits easily under 1000 bytes
        DB::statement("
            ALTER TABLE deposits
            ADD INDEX deposits_spi_sc_idx (stripe_payment_intent, stripe_charge)
        ");
    }

    public function down(): void
    {
        // Drop the composite index and revert columns to utf8mb4 if you want
        DB::statement("ALTER TABLE deposits DROP INDEX deposits_spi_sc_idx");

        DB::statement("
            ALTER TABLE deposits
            MODIFY stripe_payment_intent VARCHAR(255)
                CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL
        ");
        DB::statement("
            ALTER TABLE deposits
            MODIFY stripe_charge VARCHAR(255)
                CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL
        ");
    }
};
