<?php

namespace Dipper\Foundation\Exceptions;

use Symfony\Component\HttpFoundation\Response;
use Illuminate\Validation\Validator as IlluminateValidator;

/**
 * An exception class that supports validators by extracting their messages
 * when given, or an array of messages as strings.
 */
class InvalidInputException extends ExceptionAbstract
{
    public $httpStatusCode = Response::HTTP_BAD_REQUEST;

    public $code = -1;

    public function __construct($message = null)
    {
        if ($message instanceof IlluminateValidator) {
            $message = $message->messages()->all();
        }

        if (is_array($message)) {
            $message = implode("\n", $message);
        }

        parent::__construct($message);
    }
}
