/*
 * Seagull: A SQLite helper library
 * Copyright (C) Seagull Developers
 *
 * Seagull is the legal property of its developers, whose names are too
 * numerous to list here. Please refer to the AUTHORS file distributed with
 * this source distribution
 *
 * 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/>.
 */

#if !defined(SEAGULL_GLOBAL_HEADER_INSIDE) && !defined(SEAGULL_COMPILATION)
# error "only <seagull.h> may be included directly"
#endif

#ifndef SEAGULL_VERSION_H
#define SEAGULL_VERSION_H

#include <glib.h>

#include "seagullversionconsts.h"

/* clang-format tries to remove the space after 'if', which confuses
 * gobject-introspection, so turn it off temporarily. */
/* clang-format off */
#if (defined(_WIN32) || defined(__CYGWIN__)) && \
	!defined(SEAGULL_STATIC_COMPILATION)
/* clang-format on */
#define _SEAGULL_EXPORT __declspec(dllexport)
#define _SEAGULL_IMPORT __declspec(dllimport)
#elif __GNUC__ >= 4
#define _SEAGULL_EXPORT __attribute__((visibility("default")))
#define _SEAGULL_IMPORT
#else
#define _SEAGULL_EXPORT
#define _SEAGULL_IMPORT
#endif
#ifdef SEAGULL_COMPILATION
#define _SEAGULL_API _SEAGULL_EXPORT
#else
#define _SEAGULL_API _SEAGULL_IMPORT
#endif

#define _SEAGULL_EXTERN _SEAGULL_API extern

#ifdef SEAGULL_DISABLE_DEPRECATION_WARNINGS
#define SEAGULL_DEPRECATED _SEAGULL_EXTERN
#define SEAGULL_DEPRECATED_FOR(f) _SEAGULL_EXTERN
#define SEAGULL_UNAVAILABLE(maj, min) _SEAGULL_EXTERN
#define SEAGULL_UNAVAILABLE_MACRO(maj, min)
#define SEAGULL_UNAVAILABLE_STATIC_INLINE(maj, min)
#define SEAGULL_UNAVAILABLE_TYPE(maj, min)
#else
#define SEAGULL_DEPRECATED G_DEPRECATED _SEAGULL_EXTERN
#define SEAGULL_DEPRECATED_FOR(f) G_DEPRECATED_FOR(f) _SEAGULL_EXTERN
#define SEAGULL_UNAVAILABLE(maj, min) G_UNAVAILABLE(maj, min) _SEAGULL_EXTERN
#define SEAGULL_UNAVAILABLE_MACRO(maj, min) G_UNAVAILABLE_MACRO(maj, min)
#define SEAGULL_UNAVAILABLE_STATIC_INLINE(maj, min) G_UNAVAILABLE(maj, min)
#define SEAGULL_UNAVAILABLE_TYPE(maj, min) G_UNAVAILABLE(maj, min)
#endif

/**
 * SEAGULL_VERSION_MIN_REQUIRED:
 *
 * A macro that should be defined by the user prior to including the `seagull.h`
 * header.
 *
 * The definition should be one of the predefined Seagull version macros:
 * %SEAGULL_VERSION_0_1, %SEAGULL_VERSION_0_2, ...
 *
 * This macro defines the earliest version of Seagull that the package is required
 * to be able to compile against.
 *
 * If the compiler is configured to warn about the use of deprecated functions,
 * then using functions that were deprecated in version
 * %SEAGULL_VERSION_MIN_REQUIRED or earlier will cause warnings (but using
 * functions deprecated in later releases will not).
 *
 * Since: 0.1
 */

/**
 * SEAGULL_VERSION_CUR_STABLE:
 *
 * A macro that evaluates to the current stable version of seagull, in a format
 * that can be used by the C pre-processor.
 *
 * Since: 0.1
 */
#define SEAGULL_VERSION_CUR_STABLE \
	(G_ENCODE_VERSION(SEAGULL_MAJOR_VERSION, SEAGULL_MINOR_VERSION))

/* If the package sets SEAGULL_VERSION_MIN_REQUIRED to some future
 * SEAGULL_VERSION_X_Y value that we don't know about, it will compare as 0 in
 * preprocessor tests.
 */
#ifndef SEAGULL_VERSION_MIN_REQUIRED
#define SEAGULL_VERSION_MIN_REQUIRED (SEAGULL_VERSION_CUR_STABLE)
#elif SEAGULL_VERSION_MIN_REQUIRED == 0
#undef SEAGULL_VERSION_MIN_REQUIRED
#define SEAGULL_VERSION_MIN_REQUIRED (SEAGULL_VERSION_CUR_STABLE + 1)
#endif /* SEAGULL_VERSION_MIN_REQUIRED */

#if !defined(SEAGULL_VERSION_MAX_ALLOWED) || (SEAGULL_VERSION_MAX_ALLOWED == 0)
#undef SEAGULL_VERSION_MAX_ALLOWED
#define SEAGULL_VERSION_MAX_ALLOWED (SEAGULL_VERSION_CUR_STABLE)
#endif /* SEAGULL_VERSION_MAX_ALLOWED */

/* sanity checks */
#if SEAGULL_VERSION_MIN_REQUIRED > SEAGULL_VERSION_CUR_STABLE
#error "SEAGULL_VERSION_MIN_REQUIRED must be <= SEAGULL_VERSION_CUR_STABLE"
#endif
#if SEAGULL_VERSION_MAX_ALLOWED < SEAGULL_VERSION_MIN_REQUIRED
#error "SEAGULL_VERSION_MAX_ALLOWED must be >= SEAGULL_VERSION_MIN_REQUIRED"
#endif
#if SEAGULL_VERSION_MIN_REQUIRED < G_ENCODE_VERSION(0, 1)
#error "SEAGULL_VERSION_MIN_REQUIRED must be >= SEAGULL_VERSION_0_1"
#endif

#define SEAGULL_VAR _SEAGULL_EXTERN
#define SEAGULL_AVAILABLE_IN_ALL _SEAGULL_EXTERN

/**
 * SEAGULL_VERSION_0_1:
 *
 * A macro that evaluates to the 0.1 version of seagull, in a format that can
 * be used by the C pre-processor.
 *
 * Since: 0.1
 */
#define SEAGULL_VERSION_0_1 (G_ENCODE_VERSION(0, 1))

#if SEAGULL_VERSION_MAX_ALLOWED < SEAGULL_VERSION_0_1
#define SEAGULL_AVAILABLE_IN_0_1 SEAGULL_UNAVAILABLE(0, 1)
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_1 SEAGULL_UNAVAILABLE_ENUMERATOR(0, 1)
#define SEAGULL_AVAILABLE_MACRO_IN_0_1 SEAGULL_UNAVAILABLE_MACRO(0, 1)
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_1 SEAGULL_UNAVAILABLE_STATIC_INLINE(0, 1)
#define SEAGULL_AVAILABLE_TYPE_IN_0_1 SEAGULL_UNAVAILABLE_TYPE(0, 1)
#else
#define SEAGULL_AVAILABLE_IN_0_1 _SEAGULL_EXTERN
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_1
#define SEAGULL_AVAILABLE_MACRO_IN_0_1
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_1
#define SEAGULL_AVAILABLE_TYPE_IN_0_1
#endif

/**
 * SEAGULL_VERSION_0_2:
 *
 * A macro that evaluates to the 0.2 version of seagull, in a format that can
 * be used by the C pre-processor.
 *
 * Since: 0.2
 */
#define SEAGULL_VERSION_0_2 (G_ENCODE_VERSION(0, 2))

#if SEAGULL_VERSION_MAX_ALLOWED < SEAGULL_VERSION_0_2
#define SEAGULL_AVAILABLE_IN_0_2 SEAGULL_UNAVAILABLE(0, 2)
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_2 SEAGULL_UNAVAILABLE_ENUMERATOR(0, 2)
#define SEAGULL_AVAILABLE_MACRO_IN_0_2 SEAGULL_UNAVAILABLE_MACRO(0, 2)
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_2 SEAGULL_UNAVAILABLE_STATIC_INLINE(0, 2)
#define SEAGULL_AVAILABLE_TYPE_IN_0_2 SEAGULL_UNAVAILABLE_TYPE(0, 2)
#else
#define SEAGULL_AVAILABLE_IN_0_2 _SEAGULL_EXTERN
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_2
#define SEAGULL_AVAILABLE_MACRO_IN_0_2
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_2
#define SEAGULL_AVAILABLE_TYPE_IN_0_2
#endif

/**
 * SEAGULL_VERSION_0_3:
 *
 * A macro that evaluates to the 0.3 version of seagull, in a format that can
 * be used by the C pre-processor.
 *
 * Since: 0.3
 */
#define SEAGULL_VERSION_0_3 (G_ENCODE_VERSION(0, 3))

#if SEAGULL_VERSION_MAX_ALLOWED < SEAGULL_VERSION_0_3
#define SEAGULL_AVAILABLE_IN_0_3 SEAGULL_UNAVAILABLE(0, 3)
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_3 SEAGULL_UNAVAILABLE_ENUMERATOR(0, 3)
#define SEAGULL_AVAILABLE_MACRO_IN_0_3 SEAGULL_UNAVAILABLE_MACRO(0, 3)
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_3 SEAGULL_UNAVAILABLE_STATIC_INLINE(0, 3)
#define SEAGULL_AVAILABLE_TYPE_IN_0_3 SEAGULL_UNAVAILABLE_TYPE(0, 3)
#else
#define SEAGULL_AVAILABLE_IN_0_3 _SEAGULL_EXTERN
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_3
#define SEAGULL_AVAILABLE_MACRO_IN_0_3
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_3
#define SEAGULL_AVAILABLE_TYPE_IN_0_3
#endif

/**
 * SEAGULL_VERSION_0_4:
 *
 * A macro that evaluates to the 0.4 version of seagull, in a format that can
 * be used by the C pre-processor.
 *
 * Since: 0.4
 */
#define SEAGULL_VERSION_0_4 (G_ENCODE_VERSION(0, 4))

#if SEAGULL_VERSION_MAX_ALLOWED < SEAGULL_VERSION_0_4
#define SEAGULL_AVAILABLE_IN_0_4 SEAGULL_UNAVAILABLE(0, 4)
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_4 SEAGULL_UNAVAILABLE_ENUMERATOR(0, 4)
#define SEAGULL_AVAILABLE_MACRO_IN_0_4 SEAGULL_UNAVAILABLE_MACRO(0, 4)
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_4 SEAGULL_UNAVAILABLE_STATIC_INLINE(0, 4)
#define SEAGULL_AVAILABLE_TYPE_IN_0_4 SEAGULL_UNAVAILABLE_TYPE(0, 4)
#else
#define SEAGULL_AVAILABLE_IN_0_4 _SEAGULL_EXTERN
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_4
#define SEAGULL_AVAILABLE_MACRO_IN_0_4
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_4
#define SEAGULL_AVAILABLE_TYPE_IN_0_4
#endif

/**
 * SEAGULL_VERSION_0_5:
 *
 * A macro that evaluates to the 0.5 version of seagull, in a format that can
 * be used by the C pre-processor.
 *
 * Since: 0.5
 */
#define SEAGULL_VERSION_0_5 (G_ENCODE_VERSION(0, 5))

#if SEAGULL_VERSION_MAX_ALLOWED < SEAGULL_VERSION_0_5
#define SEAGULL_AVAILABLE_IN_0_5 SEAGULL_UNAVAILABLE(0, 5)
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_5 SEAGULL_UNAVAILABLE_ENUMERATOR(0, 5)
#define SEAGULL_AVAILABLE_MACRO_IN_0_5 SEAGULL_UNAVAILABLE_MACRO(0, 5)
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_5 SEAGULL_UNAVAILABLE_STATIC_INLINE(0, 5)
#define SEAGULL_AVAILABLE_TYPE_IN_0_5 SEAGULL_UNAVAILABLE_TYPE(0, 5)
#else
#define SEAGULL_AVAILABLE_IN_0_5 _SEAGULL_EXTERN
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_5
#define SEAGULL_AVAILABLE_MACRO_IN_0_5
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_5
#define SEAGULL_AVAILABLE_TYPE_IN_0_5
#endif

/**
 * SEAGULL_VERSION_0_6:
 *
 * A macro that evaluates to the 0.6 version of seagull, in a format that can
 * be used by the C pre-processor.
 *
 * Since: 0.6
 */
#define SEAGULL_VERSION_0_6 (G_ENCODE_VERSION(0, 6))

#if SEAGULL_VERSION_MAX_ALLOWED < SEAGULL_VERSION_0_6
#define SEAGULL_AVAILABLE_IN_0_6 SEAGULL_UNAVAILABLE(0, 6)
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_6 SEAGULL_UNAVAILABLE_ENUMERATOR(0, 6)
#define SEAGULL_AVAILABLE_MACRO_IN_0_6 SEAGULL_UNAVAILABLE_MACRO(0, 6)
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_6 SEAGULL_UNAVAILABLE_STATIC_INLINE(0, 6)
#define SEAGULL_AVAILABLE_TYPE_IN_0_6 SEAGULL_UNAVAILABLE_TYPE(0, 6)
#else
#define SEAGULL_AVAILABLE_IN_0_6 _SEAGULL_EXTERN
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_6
#define SEAGULL_AVAILABLE_MACRO_IN_0_6
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_6
#define SEAGULL_AVAILABLE_TYPE_IN_0_6
#endif

/**
 * SEAGULL_VERSION_0_7:
 *
 * A macro that evaluates to the 0.7 version of seagull, in a format that can
 * be used by the C pre-processor.
 *
 * Since: 0.7
 */
#define SEAGULL_VERSION_0_7 (G_ENCODE_VERSION(0, 7))

#if SEAGULL_VERSION_MAX_ALLOWED < SEAGULL_VERSION_0_7
#define SEAGULL_AVAILABLE_IN_0_7 SEAGULL_UNAVAILABLE(0, 7)
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_7 SEAGULL_UNAVAILABLE_ENUMERATOR(0, 7)
#define SEAGULL_AVAILABLE_MACRO_IN_0_7 SEAGULL_UNAVAILABLE_MACRO(0, 7)
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_7 SEAGULL_UNAVAILABLE_STATIC_INLINE(0, 7)
#define SEAGULL_AVAILABLE_TYPE_IN_0_7 SEAGULL_UNAVAILABLE_TYPE(0, 7)
#else
#define SEAGULL_AVAILABLE_IN_0_7 _SEAGULL_EXTERN
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_7
#define SEAGULL_AVAILABLE_MACRO_IN_0_7
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_7
#define SEAGULL_AVAILABLE_TYPE_IN_0_7
#endif

/**
 * SEAGULL_VERSION_0_8:
 *
 * A macro that evaluates to the 0.8 version of seagull, in a format that can
 * be used by the C pre-processor.
 *
 * Since: 0.8
 */
#define SEAGULL_VERSION_0_8 (G_ENCODE_VERSION(0, 8))

#if SEAGULL_VERSION_MAX_ALLOWED < SEAGULL_VERSION_0_8
#define SEAGULL_AVAILABLE_IN_0_8 SEAGULL_UNAVAILABLE(0, 8)
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_8 SEAGULL_UNAVAILABLE_ENUMERATOR(0, 8)
#define SEAGULL_AVAILABLE_MACRO_IN_0_8 SEAGULL_UNAVAILABLE_MACRO(0, 8)
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_8 SEAGULL_UNAVAILABLE_STATIC_INLINE(0, 8)
#define SEAGULL_AVAILABLE_TYPE_IN_0_8 SEAGULL_UNAVAILABLE_TYPE(0, 8)
#else
#define SEAGULL_AVAILABLE_IN_0_8 _SEAGULL_EXTERN
#define SEAGULL_AVAILABLE_ENUMERATOR_IN_0_8
#define SEAGULL_AVAILABLE_MACRO_IN_0_8
#define SEAGULL_AVAILABLE_STATIC_INLINE_IN_0_8
#define SEAGULL_AVAILABLE_TYPE_IN_0_8
#endif

G_BEGIN_DECLS

/**
 * SEAGULL_CHECK_VERSION:
 * @major: The major version to check for.
 * @minor: The minor version to check for.
 * @micro: The micro version to check for.
 *
 * Checks the version of seagull being compiled against. See [func@check_version]
 * for a runtime check.
 *
 * Returns: %TRUE if the version is the same or newer than the passed-in
 *          version.
 *
 * Since: 0.1
 */
#define SEAGULL_CHECK_VERSION(major, minor, micro) ((major) == SEAGULL_MAJOR_VERSION && \
                                                 ((minor) < SEAGULL_MINOR_VERSION || \
                                                  ((minor) == SEAGULL_MINOR_VERSION && (micro) <= SEAGULL_MICRO_VERSION)))

/**
 * seagull_check_version:
 * @required_major: the required major version.
 * @required_minor: the required minor version.
 * @required_micro: the required micro version.
 *
 * Checks that the seagull version is compatible with the requested version.
 *
 * Returns: %NULL if the versions are compatible, or a string describing
 *          the version mismatch if not compatible.
 *
 * Since: 0.1
 */
SEAGULL_AVAILABLE_IN_ALL
const char *seagull_check_version(guint required_major, guint required_minor, guint required_micro);

/**
 * seagull_version:
 *
 * The full version string of the running seagull.
 *
 * Since: 0.1
 */
SEAGULL_VAR const char *seagull_version;

/**
 * seagull_major_version:
 *
 * The major version of the running seagull. Contrast with #SEAGULL_MAJOR_VERSION,
 * which expands at compile time to the major version of seagull being compiled
 * against.
 *
 * Since: 0.1
 */
SEAGULL_VAR const guint seagull_major_version;

/**
 * seagull_minor_version:
 *
 * The minor version of the running seagull. Contrast with #SEAGULL_MINOR_VERSION,
 * which expands at compile time to the minor version of seagull being compiled
 * against.
 *
 * Since: 0.1
 */
SEAGULL_VAR const guint seagull_minor_version;

/**
 * seagull_micro_version:
 *
 * The micro version of the running seagull. Contrast with #SEAGULL_MICRO_VERSION,
 * which expands at compile time to the micro version of seagull being compiled
 * against.
 *
 * Since: 0.1
 */
SEAGULL_VAR const guint seagull_micro_version;

G_END_DECLS

#endif /* SEAGULL_VERSION_H */
