<?php

namespace App\Services;

use App\Core\Database;

class PlatformChronicleService
{

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

$db=
Database::getInstance();

$queries=[

'events'=>
"
SELECT COUNT(*)
FROM platform_chronicle
WHERE conference_id=?
",

'snapshots'=>
"
SELECT COUNT(*)
FROM platform_timeline_snapshots
WHERE org_id=?
",

'archive'=>
"
SELECT COUNT(*)
FROM platform_archive_vault
WHERE org_id=?
",

'legacy'=>
"
SELECT COUNT(*)
FROM platform_legacy_records
WHERE org_id=?
"

];

$out=[];

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

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

$stmt->execute([

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

]);

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

}

$out[
'continuity'
]=

min(

100,

60+

(
$out[
'events'
]
/2
)

+

(
$out[
'snapshots'
]
*2
)

+

$out[
'archive'
]

);

$out[
'state'
]=

$out[
'continuity'
]>=85

?

'remembered'

:

'recording';

return $out;

}

}
