<?php

namespace App\Services;

use App\Core\Database;

class PlatformMemoryService
{

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

$db=
Database::getInstance();

$out=[];

$queries=[

'memory'=>

"

SELECT COUNT(*)

FROM platform_memory

WHERE conference_id=?

",

'learning'=>

"

SELECT COUNT(*)

FROM platform_learning

WHERE conference_id=?

",

'plans'=>

"

SELECT COUNT(*)

FROM conference_home_agent_plans

WHERE conference_id=?

",

'copilot'=>

"

SELECT COUNT(*)

FROM conference_home_copilot_sessions

WHERE conference_id=?

"

];

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

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

$stmt
->execute([

$conferenceId

]);

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

}

$out[
'adaptation'
]=

min(

100,

50+

$out[
'memory'
]

+

(
$out[
'learning'
]*2
)

);

$out[
'state'
]=

$out[
'adaptation'
]>=85

?

'adaptive'

:

'learning';

return
$out;

}

public static function remember(
int $conferenceId,
int $orgId,
int $userId
): bool
{

$db=
Database::getInstance();

return
$db
->prepare("

INSERT INTO
platform_memory(

org_id,

conference_id,

memory_key,

memory_scope,

memory_value,

created_by

)

VALUES(

?,

?,

?,

'studio',

?,

?

)

")

->execute([

$orgId,

$conferenceId,

'ctx_'.date('YmdHis'),

'Studio Snapshot',

$userId

]);

}

}
