<?php

declare(strict_types=1);

namespace App\Services\Studio;

use App\Models\Artwork;
use App\Models\ArtworkAiAssist;
use App\Models\ArtworkAiAssistEvent;

final class StudioAiAssistEventService
{
    /**
     * @param array<string, mixed> $meta
     */
    public function record(Artwork $artwork, string $eventType, array $meta = [], ?ArtworkAiAssist $assist = null): ArtworkAiAssistEvent
    {
        $assist ??= $artwork->artworkAiAssist;

        return ArtworkAiAssistEvent::query()->create([
            'artwork_ai_assist_id' => $assist?->id,
            'artwork_id' => $artwork->id,
            'user_id' => $artwork->user_id,
            'event_type' => $eventType,
            'meta' => $meta,
        ]);
    }
}