<?php
/**
 * Shared helpers for module-related admin AJAX handlers.
 *
 * @package WP_PowerSuite\Core\Http\Concerns
 * @since 1.0.0
 */

namespace WP_PowerSuite\Core\Http\Concerns;

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

trait ParsesModuleAjaxInput {

	protected function getPostedModuleId(): string {
		if ( ! isset( $_POST['module_id'] ) || $_POST['module_id'] === '' ) {
			return '';
		}

		return sanitize_key( wp_unslash( $_POST['module_id'] ) );
	}

	protected function getPostedEnableFlag(): bool {
		return isset( $_POST['enable'] ) && sanitize_text_field( wp_unslash( $_POST['enable'] ) ) === '1';
	}
}
