<?php

namespace App\Services;

use App\Core\Database;

class PlatformAtlasService
{

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

$db=
Database::getInstance();

$queries=[

'capabilities'=>
"
SELECT COUNT(*)
FROM platform_capabilities
WHERE org_id=?
",

'mature'=>
"
SELECT COUNT(*)
FROM platform_capabilities
WHERE org_id=?
AND maturity_score>=80
",

'links'=>
"
SELECT COUNT(*)
FROM platform_operating_topology
WHERE conference_id=?
",

'compass'=>
"
SELECT COUNT(*)
FROM platform_compass
WHERE org_id=?
"

];

$out=[];

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

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

$stmt->execute([

$k==='links'
?
$conferenceId
:
$orgId

]);

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

}

$out[
'coverage'
]=

$out[
'capabilities'
]

?

min(

100,

round(

(
$out[
'mature'
]
/
max(
1,
$out[
'capabilities'
]
)

)
*
100

)

+

(
$out[
'links'
]
*2
)

)

:

0;

$out[
'state'
]=

$out[
'coverage'
]>=85

?

'mapped'

:

'exploring';

return $out;

}

}
