<?php

declare(strict_types=1);

namespace SiteFort\Modules\Settings;

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

use SiteFort\Includes\Interfaces\SettingsProvider;

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

	public function get_settings_schema(): array {
		$defaults = \SiteFort\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 = \SiteFort\Modules\Scanner\Service\ScannerSettings::get_all();
		return [
			'auto_scan_frequency' => $scanner['schedule'] ?? ( \SiteFort\Modules\Scanner\Service\ScannerSettings::get_defaults()['schedule'] ?? 'daily' ),
			'scan_intensity'      => $scanner['scanIntensity'] ?? ( \SiteFort\Modules\Scanner\Service\ScannerSettings::get_defaults()['scanIntensity'] ?? 'standard' ),
		];
	}

	public function save_settings( array $values ): bool {
		$scanner = \SiteFort\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 \SiteFort\Modules\Scanner\Service\ScannerSettings::save( $scanner );
	}
}
