<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::table('reviews', function (Blueprint $table) {
            if (! Schema::hasColumn('reviews', 'reward_points')) {
                $table->unsignedInteger('reward_points')->default(0);
            }
            if (! Schema::hasColumn('reviews', 'reward_popup_message')) {
                $table->text('reward_popup_message')->nullable();
            }
            if (! Schema::hasColumn('reviews', 'reward_points_granted_at')) {
                $table->timestamp('reward_points_granted_at')->nullable();
            }
            if (! Schema::hasColumn('reviews', 'reward_popup_seen_at')) {
                $table->timestamp('reward_popup_seen_at')->nullable();
            }
        });
    }

    public function down(): void
    {
        Schema::table('reviews', function (Blueprint $table) {
            foreach ([
                'reward_popup_seen_at',
                'reward_points_granted_at',
                'reward_popup_message',
                'reward_points',
            ] as $column) {
                if (Schema::hasColumn('reviews', $column)) {
                    $table->dropColumn($column);
                }
            }
        });
    }
};
