import { RegisterToken } from "@autoplex/database";
import validate from "validate.js";

interface IValidTokenOptions {
	message: string
}

/**
 * Validate a registration token
 */
validate.validators.token = async function(value: any, options: IValidTokenOptions) {
	if (typeof options === "boolean") {
		options = <any>{};
	}
	Object.assign({
		message: "is not a valid token"
	}, options);
	if (!(await RegisterToken.isValid(value))) {
		return options.message;
	}
}
