<?php

namespace App\Services;

use App\Core\Database;

class HomepageDigitalTwinService
{

public static function simulate(
int $conferenceId
): array
{

$db=
Database::getInstance();

$out=[];

$queries=[

'blocks'=>

"

SELECT COUNT(*)

FROM conference_homepage_blocks

WHERE conference_id=?

",

'deployments'=>

"

SELECT COUNT(*)

FROM conference_home_deployments

WHERE conference_id=?

",

'branches'=>

"

SELECT COUNT(*)

FROM conference_home_branches

WHERE conference_id=?

"

];

foreach(
$queries
as $k=>$sql
){

$stmt=
$db
->prepare(
$sql
);

$stmt
->execute([

$conferenceId

]);

$out[
$k
]=
(int)
$stmt
->fetchColumn();

}

$predicted=

min(

100,

55+

(
$out[
'blocks'
]
*1.5
)

+

(
$out[
'deployments'
]
*5
)

);

$actions=[];

if(
$out[
'blocks'
]<12
){

$actions[]=
'Add content sections';

}

if(
$out[
'deployments'
]<2
){

$actions[]=
'Run staged rollout';

}

return [

'predicted_score'=>

$predicted,

'scenarios'=>

$actions,

'metrics'=>

$out

];

}

}
