<?php

declare( strict_types=1 );

namespace LolaCore\Actions\Handlers;

use LolaCore\Actions\Contracts\ActionHandlerInterface;

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

class SecurityHandler implements ActionHandlerInterface {

	public function getSupportedActions(): array {
		return array( 'audit_security' );
	}

	public function handle( string $actionId, array $params, bool $dryRun ): array {
		return match ( $actionId ) {
			'audit_security' => $this->auditSecurity( $params ),
			default          => throw new \Exception( esc_html( "SecurityHandler: unknown action '{$actionId}'." ) ),
		};
	}

	private function auditSecurity( array $params ): array {
		$admin_exists = username_exists( 'admin' );
		$anyone_can_register = get_option( 'users_can_register' );
		
		return array(
			'admin_user_exists'   => (bool) $admin_exists,
			'anyone_can_register' => (bool) $anyone_can_register,
			'force_ssl_admin'     => defined( 'FORCE_SSL_ADMIN' ) && FORCE_SSL_ADMIN,
			'wp_debug_active'     => defined( 'WP_DEBUG' ) && WP_DEBUG,
			'ssl_active'          => is_ssl(),
		);
	}
}
