<?php

namespace App\Services;

use App\Core\Database;

class PlatformExecutiveCockpitService
{

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

$db=
Database::getInstance();

$out=[];

$queries=[

'domains'=>

"

SELECT COUNT(*)
FROM platform_domains
WHERE org_id=?

",

'systems'=>

"

SELECT COUNT(*)
FROM platform_federated_systems
WHERE org_id=?

",

'kpis'=>

"

SELECT COUNT(*)
FROM platform_executive_kpis
WHERE org_id=?

",

'events'=>

"

SELECT COUNT(*)
FROM platform_event_bus
WHERE org_id=?

"

];

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

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

$stmt
->execute([

$orgId

]);

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

}

$out[
'mission'
]=

min(

100,

60+

(
$out[
'domains'
]*3
)

+

(
$out[
'systems'
]*5
)

+

(
$out[
'kpis'
]*2
)

);

$out[
'state'
]=

$out[
'mission'
]>=85

?

'mission_ready'

:

'monitoring';

return
$out;

}

}
