<?php
/**
 * Class WPDesk_Paczkomaty_Ajax_Request
 */
class WPDesk_Paczkomaty_Ajax_Request {

	/**
	 * .
	 *
	 * @var string
	 */
	private $city;

	/**
	 * .
	 *
	 * @var string
	 */
	private $code;

	/**
	 * .
	 *
	 * @var string
	 */
	private $cod;

	/**
	 * .
	 *
	 * @var string
	 */
	private $end_of_week_collection;

	/**
	 * .
	 *
	 * @var array
	 */
	private $request;

	/**
	 * Query arg is also defined in JS var
	 *
	 * @var string
	 */
	const NONCE_ARG = 'security';

	/**
	 * WPDesk_WooCommerce_DHL_Ajax_Request constructor.
	 *
	 * @param string $nonce_name .
	 * @param array  $request .
	 */
	public function __construct( $nonce_name, $request ) {
		$this->request = $request;

		if ( check_ajax_referer( $nonce_name, self::NONCE_ARG, false ) ) {
			$this->city = $this->validate( 'city' );
			$this->code = $this->validate( 'code' );
			$this->cod  = $this->validate( 'cod' );

			$this->end_of_week_collection = $this->validate( 'end_of_week_collection' );
		}
	}

	/**
	 * .
	 *
	 * @param string $name .
	 *
	 * @return string
	 */
	private function validate( $name ) {
		if ( isset( $this->request[ $name ] ) ) {
			return sanitize_text_field( wp_unslash( $this->request[ $name ] ) );
		}
		return '';
	}


	/**
	 * .
	 *
	 * @return string
	 */
	public function get_city() {
		return $this->city;
	}

	/**
	 * .
	 *
	 * @return string
	 */
	public function get_code() {
		return $this->code;
	}

	/**
	 * .
	 *
	 * @return string
	 */
	public function get_cod() {
		return $this->cod;
	}

	/**
	 * .
	 *
	 * @return string
	 */
	public function get_end_of_week_collection() {
		return $this->end_of_week_collection;
	}

}
