"""RBIntegrations version and package information.

These variables and functions can be used to identify the version of
the module. They're largely used for packaging purposes.
"""

from __future__ import annotations


#: The version of RBIntegrations.
#:
#: This is in the format of:
#:
#: (Major, Minor, Micro, Patch, alpha/beta/rc/final, Release Number, Released)
#:
VERSION: tuple[int, int, int, int, str, int, bool] = \
    (5, 0, 1, 0, 'final', 0, True)


def get_version_string() -> str:
    """Return the version as a human-readable string.

    Returns:
        str:
        The human-readable version.
    """
    major, minor, micro, patch, tag, release_num, released = VERSION

    version = f'{major}.{minor}'

    if micro or patch:
        version += f'.{micro}'

    if patch:
        version += f'.{patch}'

    if tag != 'final':
        if tag == 'rc':
            version += f' RC{release_num}'
        else:
            version += f' {tag} {release_num}'

    if not released:
        version += ' (dev)'

    return version


def get_package_version() -> str:
    """Return the version as a Python package version string.

    Returns:
        str:
        The package version.
    """
    major, minor, micro, patch, tag, release_num = VERSION[:6]

    version = f'{major}.{minor}'

    if micro or patch:
        version += f'.{micro}'

    if patch:
        version += f'.{patch}'

    if tag != 'final':
        version += f'{tag}{release_num}'

    return version


def is_release() -> bool:
    """Return whether this is a released version.

    Returns:
        bool:
        ``True`` if this is a released version, or ``False`` if it's still
        in development.
    """
    return VERSION[6]


#: An alias for the the version information from :py:data:`VERSION`.
#:
#: This does not include the last entry in the tuple (the released state).
__version_info__ = VERSION[:-1]


#: An alias for the version used for the Python package.
__version__ = get_package_version()
