<?php
/**
 * File Path: includes/helpers/class-mbs-input-helpers.php
 *
 * Typed, sanitized accessors for $_POST and $_GET superglobals.
 * Nonce verification is the CALLER'S responsibility.
 * Do NOT use post_str() or get_str() where sanitize_textarea_field or wp_kses is required.
 * Confirmed sanitize_textarea_field callsites NOT to migrate: metabox-classification L936
 * (mbs_toc), tab-onix L183 (mbs_pub_publisher_address), tab-onix L187
 * (mbs_pub_copyright_disclaimer), taxonomy-contributor L200 (mbs_author_bio).
 *
 * @package MyBookShowroom
 * @since   1.3.5
 */
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class MBS_Input {

	public static function post_str( string $key, string $fallback = '' ): string {
		return isset( $_POST[ $key ] ) ? sanitize_text_field( wp_unslash( (string) $_POST[ $key ] ) ) : $fallback; // phpcs:ignore WordPress.Security.NonceVerification.Missing
	}

	public static function post_int( string $key, int $fallback = 0 ): int {
		return isset( $_POST[ $key ] ) ? (int) $_POST[ $key ] : $fallback; // phpcs:ignore WordPress.Security.NonceVerification.Missing
	}

	public static function post_key( string $key, string $fallback = '' ): string {
		return isset( $_POST[ $key ] ) ? sanitize_key( wp_unslash( (string) $_POST[ $key ] ) ) : $fallback; // phpcs:ignore WordPress.Security.NonceVerification.Missing
	}

	public static function get_str( string $key, string $fallback = '' ): string {
		return isset( $_GET[ $key ] ) ? sanitize_text_field( wp_unslash( (string) $_GET[ $key ] ) ) : $fallback; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
	}

	public static function get_key( string $key, string $fallback = '' ): string {
		return isset( $_GET[ $key ] ) ? sanitize_key( wp_unslash( (string) $_GET[ $key ] ) ) : $fallback; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
	}

	public static function get_int( string $key, int $fallback = 0 ): int {
		return isset( $_GET[ $key ] ) ? (int) $_GET[ $key ] : $fallback; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
	}

	public static function get_absint( string $key, int $fallback = 0 ): int {
		return isset( $_GET[ $key ] ) ? absint( $_GET[ $key ] ) : $fallback; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
	}
}
