<?php
/**
 * WordPress scan lock storage.
 *
 * @package LocalGuardScanner
 */

namespace LocalGuardScanner\Infrastructure\WordPress;

use LocalGuardScanner\Application\Scan\LockStore;

/**
 * Uses a unique network option for atomic lock creation.
 */
final class WordPressLockStore implements LockStore {
	const OPTION = 'localguard_scanner_lock';

	/** @param string $value Serialized lock. @return bool */
	public function add( $value ): bool {
		return add_site_option( self::OPTION, $value );
	}

	/** @return string|null */
	public function get(): ?string {
		$value = get_site_option( self::OPTION, null );
		return is_string( $value ) ? $value : null;
	}

	/** @param string $value Serialized lock. @return bool */
	public function update( $value ): bool {
		return update_site_option( self::OPTION, $value );
	}

	/** @return bool */
	public function delete(): bool {
		return delete_site_option( self::OPTION );
	}
}
