<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * Backfill migration to set registration_fee = fee_amount for existing courses,
     * maintaining backward compatibility before the fee_amount column is deprecated.
     *
     * Requirements: 2.1, 16.1
     */
    public function up(): void
    {
        // Set registration_fee = fee_amount for all existing courses
        DB::table('self_paced_courses')
            ->update([
                'registration_fee' => DB::raw('fee_amount'),
                'application_fee' => 0.00,
            ]);
    }

    public function down(): void
    {
        // Revert by setting registration_fee and application_fee to 0
        DB::table('self_paced_courses')
            ->update([
                'registration_fee' => 0.00,
                'application_fee' => 0.00,
            ]);
    }
};
