<?php

namespace App\Services;

use App\Core\Database;

class HomepageAuditService
{

public static function audit(
int $conferenceId
): array
{

$db=
Database::getInstance();

$result=[];

/*
localization
*/

$stmt=
$db
->prepare("

SELECT

COUNT(*)

FROM
conference_homepage_blocks

WHERE conference_id=?

AND
(
title_ar IS NULL
OR title_ar=''

)

");

$stmt
->execute([

$conferenceId

]);

$missing=
(int)
$stmt
->fetchColumn();

$result[]=[

'type'=>
'localization',

'score'=>
max(
0,
100-
($missing*5)
),

'message'=>

$missing
.
' untranslated blocks'

];

/*
accessibility
*/

$stmt=
$db
->prepare("

SELECT
COUNT(*)

FROM
conference_home_sections

WHERE conference_id=?

");

$stmt
->execute([

$conferenceId

]);

$sections=
(int)
$stmt
->fetchColumn();

$result[]=[

'type'=>
'accessibility',

'score'=>
min(
100,
40+
($sections*5)
),

'message'=>

'Section readability'

];

return
$result;

}

}
