<?php

namespace App\Services;

use App\Core\Database;

class PlatformArchiveVaultService
{

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

$db=
Database::getInstance();

$queries=[

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

'evidence'=>
"
SELECT COUNT(*)
FROM platform_evidence_chain
WHERE conference_id=?
",

'retained'=>
"
SELECT COUNT(*)
FROM platform_archive_vault
WHERE org_id=?
AND (
expires_at IS NULL
OR expires_at>=CURDATE()
)
",

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

];

$out=[];

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

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

$stmt->execute([

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

]);

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

}

$out[
'preservation'
]=

min(

100,

55+

(
$out[
'retained'
]
*2
)

+

(
$out[
'evidence'
]
*2
)

+

$out[
'legacy'
]

);

$out[
'state'
]=

$out[
'preservation'
]>=85

?

'preserved'

:

'retaining';

return $out;

}

}
