<?php
namespace Docuform\Api\Exception;

use Nyholm\Psr7\ServerRequest;
use Psr\Http\Message\ServerRequestInterface;

class ApiHttpInvalidParameter extends ApiHttpBadRequestException
{
  // 400
  public function __construct(ServerRequestInterface|null $request = null, string|null $badParameter = null, string|null $badValue = null)
  {
    $this->message = (!empty($badValue) ? 'Invalid' : 'Missing') . ' parameter';

    if (!empty($badParameter))
      $this->message .= ' ' . $badParameter;

    if (!empty($badValue))
    {
      $this->description = $this->message . ": '" . $badValue . "'";
    }

    parent::__construct($request ? $request : new ServerRequest('', ''), $this->message, $this->description);
  }
}
