<?php

namespace App\Services;

use App\Core\Database;

class PlatformGenesisService
{

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

$db=
Database::getInstance();

$out=[];

$queries=[

'modules'=>

"

SELECT COUNT(*)
FROM platform_bootstrap_modules
WHERE org_id=?
AND is_enabled=1

",

'runs'=>

"

SELECT COUNT(*)
FROM platform_genesis_runs
WHERE conference_id=?

",

'domains'=>

"

SELECT COUNT(*)
FROM platform_domains
WHERE org_id=?

",

'knowledge'=>

"

SELECT COUNT(*)
FROM platform_runtime_knowledge
WHERE conference_id=?

"

];

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

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

if(
in_array(
$k,
[
'modules',
'domains'
]
)
){

$stmt->execute([
$orgId
]);

}
else{

$stmt->execute([
$conferenceId
]);

}

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

}

$out[
'activation'
]=

min(

100,

60+

(
$out[
'modules'
]
*2
)

+

(
$out[
'runs'
]
*3
)

+

(
$out[
'knowledge'
]
/10
)

);

$out[
'state'
]=

$out[
'activation'
]>=90

?

'assembled'

:

'bootstrapping';

return
$out;

}

}
