<?php

declare(strict_types=1);

namespace SecurWP\Modules\Settings;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use SecurWP\Includes\Interfaces\SettingsProvider;

/**
 * Provider that exposes Scanner schedule/intensity settings.
 */
class ScannerSettingsProvider implements SettingsProvider {

	public function get_settings_schema(): array {
		$defaults = \SecurWP\Modules\Scanner\Service\ScannerSettings::get_defaults();
		return [
			'auto_scan_frequency' => [ 'type' => 'string', 'default' => (string) ( $defaults['schedule'] ?? 'daily' ) ],
			'scan_intensity'      => [ 'type' => 'string', 'default' => (string) ( $defaults['scanIntensity'] ?? 'standard' ) ],
		];
	}

	public function get_settings(): array {
		$scanner = \SecurWP\Modules\Scanner\Service\ScannerSettings::get_all();
		return [
			'auto_scan_frequency' => $scanner['schedule'] ?? ( \SecurWP\Modules\Scanner\Service\ScannerSettings::get_defaults()['schedule'] ?? 'daily' ),
			'scan_intensity'      => $scanner['scanIntensity'] ?? ( \SecurWP\Modules\Scanner\Service\ScannerSettings::get_defaults()['scanIntensity'] ?? 'standard' ),
		];
	}

	public function save_settings( array $values ): bool {
		$scanner = \SecurWP\Modules\Scanner\Service\ScannerSettings::get_all();

		if ( isset( $values['auto_scan_frequency'] ) ) {
			$scanner['schedule'] = $values['auto_scan_frequency'];
		}
		if ( isset( $values['scan_intensity'] ) ) {
			$scanner['scanIntensity'] = $values['scan_intensity'];
		}

		return \SecurWP\Modules\Scanner\Service\ScannerSettings::save( $scanner );
	}
}
