/**
 * Checks whether a passed queue number has valid sintax
 *
 * @param v_queue The queue to check format
 * @return %TRUE if it's well formated
 **/
USE pbx;
DROP PROCEDURE IF EXISTS queue_is_valid;
DELIMITER $$
CREATE PROCEDURE queue_is_valid (v_queue VARCHAR(255))
BEGIN
	DECLARE v_is_valid BOOLEAN;

	SET v_is_valid = v_queue IS NULL
		OR v_queue REGEXP '^[1-9][0-9]00$';

	IF NOT v_is_valid
	THEN
		SIGNAL SQLSTATE '45000'
			SET MESSAGE_TEXT = 'QUEUE_INVALID_FORMAT';
	END IF;
END$$
DELIMITER ;
