<?php

namespace Khofmann\Input;

use Khofmann\Request\Request;

/**
 * Facade for Input (wraps SimpleRouter)
 */
class Input
{
  /**
   * Private since facade.
   */
  private function __construct()
  {
  }

  /**
   * Get POST parameter.
   *
   * @param string $index Parameter name
   * @param mixed $defaultValue Default value if parameter was null
   */
  public static function post(string $index, $defaultValue = null)
  {
    $value = Request::request()->getInputHandler()->post($index, $defaultValue);
    return !is_object($value) ? $value : $value->getValue();
  }

  /**
   * Get PATCH parameter.
   *
   * @param string $index Parameter name
   * @param mixed $defaultValue Default value if parameter was null
   */
  public static function patch(string $index, $defaultValue = null)
  {
    $value = Request::request()->getInputHandler()->post($index, $defaultValue);
    return !is_object($value) ? $value : $value->getValue();
  }

  /**
   * Get query string parameter.
   *
   * @param string $index Parameter name
   * @param mixed $defaultValue Default value if parameter was null
   */
  public static function get(string $index, $defaultValue = null)
  {
    $value = Request::request()->getInputHandler()->get($index, $defaultValue);
    return !is_object($value) ? $value : $value->getValue();
  }

  /**
   * Get FILE entry.
   *
   * @param string $index File name
   * @param mixed $defaultValue Default value if parameter was null
   */
  public static function file(string $index, $defaultValue = null)
  {
    $value = Request::request()->getInputHandler()->file($index, $defaultValue);
    return $value;
  }
}
