<?php

namespace App\Services;

use App\Core\Database;

class HomepageKnowledgeService
{

public static function insights(
int $conferenceId,
int $orgId
): array
{

$db=
Database::getInstance();

$out=[];

$sql=[

'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(
$sql
as $k=>$q
){

$s=
$db
->prepare(
$q
);

$s
->execute([

$conferenceId

]);

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

}

$recommendations=[];

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

$recommendations[]=
'Add more homepage blocks';

}

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

$recommendations[]=
'Create staged deployment';

}

if(
$out[
'branches'
]
<1
){

$recommendations[]=
'Use branch workflow';

}

return [

'score'=>

min(

100,

50+

$out[
'blocks'
]

+

(
$out[
'deployments'
]
*10
)

),

'recommendations'=>

$recommendations,

'metrics'=>

$out

];

}

}
