<?php

declare(strict_types=1);

namespace App\Services\SupportCenter;

use DBCore\Setting\Contracts\SettingManagerInterface;

/**
 * 持久化最近一次远程站点绑定状态快照。
 */
final class HostSiteOnboardingStatusCacheStore
{
    public const SETTING_KEY = 'dberp.host.site_onboarding.last_status_snapshot';

    public function __construct(
        private readonly SettingManagerInterface $settingManager,
    ) {}

    /**
     * @return array<string, mixed>|null
     */
    public function get(): ?array
    {
        $value = $this->settingManager->get(self::SETTING_KEY);

        return is_array($value) ? $value : null;
    }

    /**
     * @param  array<string, mixed>  $snapshot
     */
    public function store(array $snapshot): void
    {
        $this->settingManager->set(
            self::SETTING_KEY,
            SupportCenterSnapshotSanitizer::sanitize($snapshot),
        );
    }
}
