<?php

namespace App\Services;

use App\Core\Database;

class HomepageCommandBus
{

public static function dispatch(
int $conferenceId,
string $command,
array $payload,
int $userId
)
{

$db=
Database::getInstance();

return
$db
->prepare("

INSERT INTO
conference_home_commands(

conference_id,

command_name,

payload_json,

created_by

)

VALUES(

?,

?,

?,

?

)

")

->execute([

$conferenceId,

$command,

json_encode(
$payload,
JSON_UNESCAPED_UNICODE
),

$userId

]);

}

public static function latest(
int $conferenceId
)
{

$db=
Database::getInstance();

$stmt=
$db
->prepare("

SELECT *

FROM
conference_home_commands

WHERE conference_id=?

ORDER BY id DESC

LIMIT 1

");

$stmt
->execute([

$conferenceId

]);

return
$stmt
->fetch()

??

[];

}

}
