<?php

namespace App\Services;

use App\Core\Database;

class HomepageAgentService
{

public static function plan(
int $conferenceId,
int $userId,
string $goal
): array
{

$db=
Database::getInstance();

$steps=[];

$map=[

'publish'=>

[
'Validate draft',
'Run review',
'Prepare deployment'
],

'homepage'=>

[
'Review sections',
'Improve content',
'Create branch'
],

'default'=>

[
'Analyze',
'Recommend',
'Prepare approval'
]

];

$key='default';

if(
str_contains(
strtolower($goal),
'publish'
)
){
$key='publish';
}

if(
str_contains(
strtolower($goal),
'homepage'
)
){
$key='homepage';
}

$steps=
$map[$key];

$payload=[

'goal'=>$goal,

'steps'=>$steps

];

$db
->prepare("

INSERT INTO
conference_home_agent_plans(

conference_id,

requested_by,

goal_text,

plan_json

)

VALUES(

?,

?,

?,

?

)

")

->execute([

$conferenceId,

$userId,

$goal,

json_encode(
$payload,
JSON_UNESCAPED_UNICODE
)

]);

return $payload;

}

}
