<?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::create('artwork_ai_assist_events', function (Blueprint $table): void {
            $table->id();
            $table->foreignId('artwork_ai_assist_id')->nullable()->constrained('artwork_ai_assists')->nullOnDelete();
            $table->foreignId('artwork_id')->constrained('artworks')->cascadeOnDelete();
            $table->foreignId('user_id')->constrained('users')->cascadeOnDelete();
            $table->string('event_type', 64)->index();
            $table->json('meta')->nullable();
            $table->timestamps();

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

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