* SPDX-License-Identifier: AGPL-3.0-or-later */ namespace KTXM\ProviderImap\Providers; enum ServiceMode: string { case Live = 'live'; case Cached = 'cached'; } enum CacheSyncStrategy: string { case Manual = 'manual'; case Interval = 'interval'; case Push = 'push'; } /** * Per-service operational settings for the IMAP provider. * * - debug: Attach a PSR-3 logger to the IMAP client when true * - mode: live (all reads/writes hit IMAP) | cached (reads from MongoDB) * - cacheSync: How the cache is kept fresh (only relevant in cached mode) */ class ServiceSettings { public function __construct( private bool $debug = false, private ServiceMode $mode = ServiceMode::Live, private CacheSyncStrategy $cacheSync = CacheSyncStrategy::Interval, ) {} // ── Serialisation ──────────────────────────────────────────────────────── public function toStore(): array { return [ 'debug' => $this->debug, 'mode' => $this->mode->value, 'cacheSync' => $this->cacheSync->value, ]; } public function fromStore(array $data): static { $this->debug = $data['debug'] ?? false; $this->mode = ServiceMode::from($data['mode'] ?? ServiceMode::Live->value); $this->cacheSync = CacheSyncStrategy::from($data['cacheSync'] ?? CacheSyncStrategy::Interval->value); return $this; } public function jsonSerialize(): array { return $this->toStore(); } public function jsonDeserialize(array|string $data): static { if (is_string($data)) { $data = json_decode($data, true); } return $this->fromStore($data); } // ── Accessors ──────────────────────────────────────────────────────────── public function getDebug(): bool { return $this->debug; } public function setDebug(bool $v): static { $this->debug = $v; return $this; } public function getMode(): ServiceMode { return $this->mode; } public function setMode(ServiceMode $v): static { $this->mode = $v; return $this; } public function getCacheSync(): CacheSyncStrategy { return $this->cacheSync; } public function setCacheSync(CacheSyncStrategy $v): static { $this->cacheSync = $v; return $this; } }