<?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('artwork_stats', function (Blueprint $table) {
            $table->double('heat_score')->default(0)->after('engagement_velocity');
            $table->timestamp('heat_score_updated_at')->nullable()->after('heat_score');
            $table->unsignedInteger('views_1h')->default(0)->after('heat_score_updated_at');
            $table->unsignedInteger('favourites_1h')->default(0)->after('views_1h');
            $table->unsignedInteger('comments_1h')->default(0)->after('favourites_1h');
            $table->unsignedInteger('shares_1h')->default(0)->after('comments_1h');
            $table->unsignedInteger('downloads_1h')->default(0)->after('shares_1h');

            $table->index('heat_score', 'idx_artwork_stats_heat_score');
        });
    }

    public function down(): void
    {
        Schema::table('artwork_stats', function (Blueprint $table) {
            $table->dropIndex('idx_artwork_stats_heat_score');
            $table->dropColumn([
                'heat_score',
                'heat_score_updated_at',
                'views_1h',
                'favourites_1h',
                'comments_1h',
                'shares_1h',
                'downloads_1h',
            ]);
        });
    }
};
