<?php

namespace App\Services;

use App\Core\Database;

class PlatformStrategicCommandService
{

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

$db=
Database::getInstance();

$out=[];

$queries=[

'objectives'=>

"

SELECT COUNT(*)

FROM platform_strategy_map

WHERE org_id=?

",

'completed'=>

"

SELECT COUNT(*)

FROM platform_strategy_map

WHERE org_id=?

AND progress_percent>=100

",

'twins'=>

"

SELECT COUNT(*)

FROM platform_university_twin

WHERE org_id=?

",

'kpis'=>

"

SELECT COUNT(*)

FROM platform_executive_kpis

WHERE org_id=?

"

];

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

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

$stmt
->execute([

$orgId

]);

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

}

$out[
'strategy'
]=

$out[
'objectives'
]

?

min(

100,

round(

(
$out[
'completed'
]
/
max(
1,
$out[
'objectives'
]
)

)
*
100

)

+

(
$out[
'twins'
]*3
)

)

:

0;

$out[
'state'
]=

$out[
'strategy'
]>=80

?

'command_ready'

:

'planning';

return
$out;

}

}
