protected function configureAndReturn(ValidatorContract $validator, array $rules, $resource=null)
    {

        if (!$rules && !$resource) {
            return $validator;
        }

        if ($validator instanceof AlterableContract) {

            $validator = $rules ? $validator->mergeRules($rules) : $validator;

            // Special case of implement both interfaces
            if ($validator instanceof GenericValidator && $resource) {
                $validator->setResource($resource);
            }

            return $validator;

        }

        if (!$validator instanceof GenericContract) {
            $name = get_class($validator);
            throw new UnsupportedParameterException("The validator '$name' does not support setting, merging rules or setting a resource.");
        }

        if ($resource) {
            $validator->setResource($resource);
        }

        return $validator->setRules($rules);

    }