<?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
    {
        if (! Schema::hasTable('artwork_bookmarks')) {
            Schema::create('artwork_bookmarks', function (Blueprint $table): void {
                $table->id();
                $table->foreignId('artwork_id')->constrained('artworks')->cascadeOnDelete();
                $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
                $table->timestamps();

                $table->unique(['artwork_id', 'user_id']);
                $table->index(['user_id', 'created_at']);
            });
        }
    }

    public function down(): void
    {
        Schema::dropIfExists('artwork_bookmarks');
    }
};