<?php

declare(strict_types=1);

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('collection_saves', function (Blueprint $table): void {
            $table->timestamp('last_viewed_at')->nullable()->after('created_at');
            $table->string('save_context', 80)->nullable()->after('last_viewed_at');
            $table->json('save_context_meta_json')->nullable()->after('save_context');

            $table->index(['user_id', 'last_viewed_at'], 'collection_saves_user_last_viewed_idx');
        });
    }

    public function down(): void
    {
        Schema::table('collection_saves', function (Blueprint $table): void {
            $table->dropIndex('collection_saves_user_last_viewed_idx');
            $table->dropColumn([
                'last_viewed_at',
                'save_context',
                'save_context_meta_json',
            ]);
        });
    }
};