<?php
 namespace Modules\Reports\AriaReports\Model; abstract class RequestAbstract { public string $aiModel = 'gpt-5.1-2025-11-13'; protected string $userPrompt; protected string $systemRole; protected array $prevChatMessages = []; public function __construct(string $userPrompt) { $this->userPrompt = $userPrompt; $this->init(); } public function setPrevChatMessages(array $prevChatMessages): void { $this->prevChatMessages = $prevChatMessages; } abstract protected function init(): void; public function getBody(): array { if (!$this->userPrompt) { throw new \RuntimeException('No input provided.'); } if (!isset($this->systemRole)) { throw new \Exception('No system role provided.'); } $this->checkInput(); $body = [ 'model' => $this->aiModel, 'input' => [ [ 'type' => 'message', 'role'=>'system', 'content' => $this->systemRole, ], ], ]; foreach($this->prevChatMessages as $message) { $body['input'][] = [ 'type' => 'message', 'role' => 'user', 'content' => $message['userPrompt'], ]; if ($message['textReply']) { $body['input'][] = [ 'type' => 'message', 'role' => 'assistant', 'content' => $message['textReply'], ]; } } $body['input'][] = [ 'type' => 'message', 'role'=>'user', 'content' => $this->userPrompt, ]; $this->populateBody($body); return $body; } abstract protected function checkInput(): void; abstract protected function populateBody(array &$body): void; }