<?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
    {
        // Update existing bonus_gold to bonus_gold_fixed for backward compatibility
        DB::table('pw_promo')
            ->where('discount_type', 'bonus_gold')
            ->update(['discount_type' => 'bonus_gold_fixed']);

        // Modify enum using raw SQL (more reliable for production)
        DB::statement("
            ALTER TABLE pw_promo MODIFY COLUMN discount_type 
            ENUM('percentage', 'fixed', 'bonus_gold_fixed', 'bonus_gold_percentage') 
            DEFAULT 'percentage'
        ");
    }

    public function down(): void
    {
        // Revert bonus_gold_fixed back to bonus_gold
        DB::table('pw_promo')
            ->where('discount_type', 'bonus_gold_fixed')
            ->update(['discount_type' => 'bonus_gold']);

        // Revert enum back to old options
        DB::statement("
            ALTER TABLE pw_promo MODIFY COLUMN discount_type 
            ENUM('percentage', 'fixed', 'bonus_gold') 
            DEFAULT 'percentage'
        ");
    }
};
