<?php

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

return new class extends Migration
{
    public function up(): void
    {
        $rows = DB::table('class_courses')
            ->select(['id', 'name', 'classroom'])
            ->whereNull('classroom')
            ->orWhere('classroom', '')
            ->orderBy('id')
            ->get();

        foreach ($rows as $row) {
            $name = (string) ($row->name ?? '');
            $classroom = str_contains($name, '飛輪') ? '飛輪教室' : '有氧團體教室';

            DB::table('class_courses')
                ->where('id', $row->id)
                ->update(['classroom' => $classroom]);
        }
    }

    public function down(): void
    {
        // No-op: do not clear user-entered classroom values.
    }
};
