<?php
namespace App\AI\Contexts\Entity; abstract class EntityAbstract extends \App\AI\Contexts\ContextAbstract { abstract protected function populateFunctionInsertUpdateParameters( \App\AI\Api\ChatGpt\Responses\Parameters|\App\AI\Api\ChatGpt\Responses\Property $paramsObj ) : \App\AI\Api\ChatGpt\Responses\Parameters|\App\AI\Api\ChatGpt\Responses\Property; protected function getCreateEntityDraft(array $args): array { $draft_id = rand(1000, 9999); $cacheKey = __CLASS__ .'_'. $draft_id; $draft = []; $draft['draft_id'] = $draft_id; $draft['fields'] = []; $draft['missing_required_fields'] = []; foreach ($this->entityFields as $fieldName) { if (isset($args[$fieldName])) { $draft['fields'][$fieldName] = $args[$fieldName]; } } foreach ($this->mandatoryFields as $fieldName) { if (empty($draft['fields'][$fieldName])) { $draft['missing_required_fields'][] = $fieldName; } } $this->cacheObj->set($cacheKey, json_encode($draft)); return $draft; } protected function getUpdateEntityDraft(array $args): array { $cacheKey = __CLASS__ .'_'. $args['draft_id']; $draftStr = $this->cacheObj->get($cacheKey); $draft = json_decode($draftStr, true); foreach ($this->entityFields as $fieldName) { if (isset($args['patch'][$fieldName])) { $draft['fields'][$fieldName] = $args['patch'][$fieldName]; } } $draft['missing_required_fields'] = []; foreach ($this->mandatoryFields as $fieldName) { if (empty($draft['fields'][$fieldName])) { $draft['missing_required_fields'][] = $fieldName; } } $this->cacheObj->set($cacheKey, json_encode($draft)); return $draft; } protected function getPreviewEntityDraft(array $args): array { $cacheKey = __CLASS__ .'_'. $args['draft_id']; $draftStr = $this->cacheObj->get($cacheKey); $draft = json_decode($draftStr, true); $draft['is_ready'] = !$draft['missing_required_fields']; return $draft; } protected function determineOperationAvailability(\App\Entity\GeneralAbstract $entity, \App\MessagesCollector $msgs) { $available = null; try { $entity->isAvailable(); $available = true; } catch (\App\Entity\Exception $ex) { $msgs->appendMessages($ex->getMessagesCollector()); $available = false; } return $available; } } 