<?php

namespace App\Services;

use App\Core\Database;

class HomepageCertificationService
{

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

$db=
Database::getInstance();

$score=
100;

$issues=[];

/*
hero
*/

$q=
$db
->prepare("

SELECT COUNT(*)

FROM
conference_homepage_blocks

WHERE conference_id=?

AND block_key='hero'

");

$q
->execute([

$conferenceId

]);

if(
!(int)
$q->fetchColumn()
){

$score-=20;

$issues[]=
'Hero missing';

}

/*
branding
*/

$q=
$db
->prepare("

SELECT COUNT(*)

FROM
conference_home_sections

WHERE conference_id=?

");

$q
->execute([

$conferenceId

]);

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

if(
$sections<6
){

$score-=10;

$issues[]=
'Homepage too short';

}

$status=

$score>=90
?

'certified'

:

(
$score>=70

?

'review'

:

'failed'
);

return [

'score'=>
max(
0,
$score
),

'status'=>
$status,

'issues'=>
$issues

];

}

}
