<?php

declare(strict_types=1);

namespace ApiModel\Infrastructure\Queue;

use ApiModel\Infrastructure\Persistence\Database;
use PDO;

final class InAppNotificationWriter
{
    /**
     * @param list<array{user_id: string, type: string, title: string, body: string, claim_id?: ?string}> $items
     */
    public static function insertBatch(PDO $pdo, array $items): void
    {
        if ($items === []) {
            return;
        }

        $st = $pdo->prepare(
            'INSERT INTO notifications (id, user_id, type, title, body, claim_id, is_read) VALUES (?,?,?,?,?,?,0)',
        );
        foreach ($items as $row) {
            $st->execute([
                Database::uuid(),
                $row['user_id'],
                $row['type'],
                $row['title'],
                $row['body'],
                $row['claim_id'] ?? null,
            ]);
        }
    }
}
