<?php

namespace App\Services;

use App\Core\Database;

class PlatformNexusService
{

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

$db=
Database::getInstance();

$out=[];

$queries=[

'domains'=>

"

SELECT COUNT(*)

FROM platform_domains

WHERE org_id=?

",

'links'=>

"

SELECT COUNT(*)

FROM platform_nexus_links

WHERE org_id=?

",

'systems'=>

"

SELECT COUNT(*)

FROM platform_federated_systems

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[
'mesh'
]=

min(

100,

55+

(
$out[
'domains'
]*4
)

+

(
$out[
'links'
]*3
)

+

(
$out[
'systems'
]*6
)

);

$out[
'state'
]=

$out[
'mesh'
]>=85

?

'unified'

:

'integrating';

return
$out;

}

}
