/*
 * Copyright (C) 2023 Hasl Developers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
 */

#include "haslversion.h"

/******************************************************************************
 * Externals
 *****************************************************************************/
const guint hasl_major_version = HASL_MAJOR_VERSION;
const guint hasl_minor_version = HASL_MINOR_VERSION;
const guint hasl_micro_version = HASL_MICRO_VERSION;
const char *hasl_version = HASL_VERSION;

/******************************************************************************
 * Public API
 *****************************************************************************/
const char *
hasl_check_version(guint required_major, guint required_minor,
                   guint required_micro)
{
	if(required_major > HASL_MAJOR_VERSION) {
		return "hasl version too old (major mismatch)";
	}

#if HASL_CHECK_VERSION(1, 0, 0)
	if(required_major < HASL_MAJOR_VERSION) {
		return "hasl version too new (major mismatch)";
	}
#endif

	if(required_minor > HASL_MINOR_VERSION) {
		return "hasl version too old (minor mismatch)";
	}

	if((required_minor == HASL_MINOR_VERSION) &&
	   (required_micro > HASL_MICRO_VERSION))
	{
		return "hasl version too old (micro mismatch)";
	}

	return NULL;
}
