<?php

namespace App\Domains\QrCode\Actions;

use App\Domains\QrCode\Models\QrCode;
use App\Domains\QrCode\Services\QrRenderer;
use App\Models\User;

class GenerateQrCode
{
    public function __construct(private readonly QrRenderer $renderer) {}

    /**
     * @param  array<string, mixed>  $payload
     * @param  array<string, mixed>  $style
     */
    public function handle(
        int $workspaceId,
        string $type,
        array $payload,
        array $style,
        User $creator,
        ?int $linkId = null,
    ): QrCode {
        return QrCode::create([
            'workspace_id' => $workspaceId,
            'link_id' => $linkId,
            'type' => $type,
            'payload' => $payload,
            'style' => $style ?: null,
            'created_by' => $creator->id,
        ]);
    }
}
