feat: implement preview configuration

Signed-off-by: Sebastian Krupinski <krupinski01@gmail.com>
This commit is contained in:
2026-08-29 07:53:14 -04:00
parent 30a8eddf06
commit eaea5f4c83
6 changed files with 398 additions and 0 deletions
@@ -0,0 +1,72 @@
<?php
declare(strict_types=1);
namespace KTXC\Models\Tenant;
use InvalidArgumentException;
use KTXF\Json\JsonSerializableObject;
final class TenantPreviewGeneration extends JsonSerializableObject
{
public const MODE_LAZY = 'lazy';
public const MODE_EAGER_WITH_LAZY_FALLBACK = 'eager-with-lazy-fallback';
protected string $mode = self::MODE_EAGER_WITH_LAZY_FALLBACK;
protected int $maxSourceSize = 104857600;
protected int $timeoutSeconds = 30;
protected int $retryDelaySeconds = 3600;
public function jsonDeserialize(array|string $data): static
{
if (is_string($data)) {
$data = json_decode($data, true, flags: JSON_THROW_ON_ERROR);
}
if (array_key_exists('mode', $data)) {
if (!is_string($data['mode']) || !in_array($data['mode'], [
self::MODE_LAZY,
self::MODE_EAGER_WITH_LAZY_FALLBACK,
], true)) {
throw new InvalidArgumentException('Unsupported preview generation mode');
}
$this->mode = $data['mode'];
}
foreach ([
'maxSourceSize' => 'maximum source size',
'timeoutSeconds' => 'timeout',
'retryDelaySeconds' => 'retry delay',
] as $property => $label) {
if (!array_key_exists($property, $data)) {
continue;
}
if (!is_int($data[$property]) || $data[$property] < 1) {
throw new InvalidArgumentException("Preview {$label} must be a positive integer");
}
$this->$property = $data[$property];
}
return $this;
}
public function mode(): string
{
return $this->mode;
}
public function maxSourceSize(): int
{
return $this->maxSourceSize;
}
public function timeoutSeconds(): int
{
return $this->timeoutSeconds;
}
public function retryDelaySeconds(): int
{
return $this->retryDelaySeconds;
}
}