feat: implement entity create and modify

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-08-15 21:16:12 -04:00
parent ae2f5c26ad
commit 9978c54431
2 changed files with 109 additions and 2 deletions
+58
View File
@@ -9,6 +9,7 @@ use KTXC\Resource\ProviderManager;
use KTXF\Mail\Collection\CollectionBaseInterface;
use KTXF\Mail\Collection\CollectionPropertiesMutableInterface;
use KTXF\Mail\Collection\ICollectionBase;
use KTXF\Mail\Entity\EntityBaseInterface;
use KTXF\Mail\Entity\IMessageBase;
use KTXF\Mail\Object\Address;
use KTXF\Mail\Object\AddressInterface;
@@ -1129,6 +1130,63 @@ class Manager {
return $operationOutcome;
}
/**
* Create a new entity in a collection.
*
* @param MessagePropertiesMutableInterface|array $properties Entity properties
*
* @throws InvalidArgumentException
*/
public function entityCreate(string $tenantId, string $userId, CollectionIdentifier $target, MessagePropertiesMutableInterface|array $properties, array $options = []): EntityBaseInterface
{
$service = $this->serviceFetch($tenantId, $userId, $target->provider(), $target->service());
if ($service->getEnabled() === false) {
throw new InvalidArgumentException("Service '{$service->identifier()}' not found or is disabled");
}
if ($service instanceof ServiceEntityMutableInterface === false) {
throw new InvalidArgumentException("Service '{$service->identifier()}' does not support entity mutations");
}
if (!$service->capable(ServiceEntityMutableInterface::CAPABILITY_ENTITY_CREATE)) {
throw new InvalidArgumentException("Service '{$service->identifier()}' is not capable of creating entities");
}
if ($properties instanceof MessagePropertiesMutableInterface === false) {
$properties = $service->entityFresh()->getProperties()->jsonDeserialize($properties);
}
return $service->entityCreate($target, $properties, $options);
}
/**
* Modify an existing entity.
*
* The returned entity identifier is authoritative and may differ from the
* target identifier for providers that use replacement semantics.
*
* @param MessagePropertiesMutableInterface|array $properties Entity properties
*
* @throws InvalidArgumentException
*/
public function entityModify(string $tenantId, string $userId, EntityIdentifier $target, MessagePropertiesMutableInterface|array $properties): EntityBaseInterface
{
$service = $this->serviceFetch($tenantId, $userId, $target->provider(), $target->service());
if ($service->getEnabled() === false) {
throw new InvalidArgumentException("Service '{$service->identifier()}' not found or is disabled");
}
if ($service instanceof ServiceEntityMutableInterface === false) {
throw new InvalidArgumentException("Service '{$service->identifier()}' does not support entity mutations");
}
if (!$service->capable(ServiceEntityMutableInterface::CAPABILITY_ENTITY_MODIFY)) {
throw new InvalidArgumentException("Service '{$service->identifier()}' is not capable of modifying entities");
}
if ($properties instanceof MessagePropertiesMutableInterface === false) {
$properties = $service->entityFresh()->getProperties()->jsonDeserialize($properties);
}
return $service->entityModify($target, $properties);
}
/**
* Deletes entities
*