<?php

namespace App\Services;

use App\Core\Database;

class HomepageEventStoreService
{

public static function record(
int $conferenceId,
string $event,
array $payload,
int $userId
)
{

$db=
Database::getInstance();

return
$db
->prepare("

INSERT INTO
conference_home_events(

conference_id,

event_name,

aggregate_type,

payload_json,

created_by

)

VALUES(

?,

?,

'homepage',

?,

?

)

")

->execute([

$conferenceId,

$event,

json_encode(
$payload,
JSON_UNESCAPED_UNICODE
),

$userId

]);

}

public static function latest(
int $conferenceId
)
{

$db=
Database::getInstance();

$stmt=
$db
->prepare("

SELECT *

FROM
conference_home_events

WHERE conference_id=?

ORDER BY id DESC

LIMIT 30

");

$stmt
->execute([

$conferenceId

]);

return
$stmt
->fetchAll();

}

}
