<?php
namespace SabaiApps\Framework\Application;

/**
 * HttpContext class extends Context to provide HTTP-specific context features.
 * Manages HTTP status, charset, content type, and redirect URL.
 */
class HttpContext extends Context {

	/**
	 * Status constant for HTTP redirect.
	 */
	const STATUS_REDIRECT = 4;

	/**
	 * @var string Character set for the response.
	 * @var string|null Content type for the response.
	 * @var string|null Redirect URL.
	 */
	protected $_charset = 'UTF-8', $_contentType, $_redirectUrl;

	/**
	 * Sets the redirect URL and updates the status to redirect.
	 *
	 * @param string $redirectUrl The URL to redirect to.
	 * @return $this
	 */
	public function setRedirect( $redirectUrl ) {
		$this->_status      = self::STATUS_REDIRECT;
		$this->_redirectUrl = $redirectUrl;

		return $this;
	}

	/**
	 * Checks if the current status is redirect.
	 *
	 * @return bool
	 */
	public function isRedirect() {
		return $this->_status === self::STATUS_REDIRECT;
	}

	/**
	 * Gets the redirect URL.
	 *
	 * @return string|null
	 */
	public function getRedirectUrl() {
		return $this->_redirectUrl;
	}

	/**
	 * Gets the character set for the response.
	 *
	 * @return string
	 */
	public function getCharset() {
		return $this->_charset;
	}

	/**
	 * Sets the character set for the response.
	 *
	 * @param string $charset
	 * @return $this
	 */
	public function setCharset( $charset ) {
		$this->_charset = $charset;

		return $this;
	}

	/**
	 * Gets the content type for the response.
	 *
	 * @return string|null
	 */
	public function getContentType() {
		return $this->_contentType;
	}

	/**
	 * Sets the content type for the response.
	 *
	 * @param string $contentType
	 * @return $this
	 */
	public function setContentType( $contentType ) {
		$this->_contentType = $contentType;

		return $this;
	}
}
