# (c) 2026 Applied Brain Research
#
# All information contained herein is and remains the property of Applied Brain
# Research. The intellectual and technical concepts contained herein are
# proprietary to Applied Brain Research and may be covered by U.S. and Foreign
# Patents, patents in process, and are protected by trade secret or copyright
# law. Dissemination of this information or reproduction of this material is
# strictly forbidden unless prior written permission is obtained from Applied
# Brain Research. Access to the source code contained herein is hereby
# forbidden to anyone except current Applied Brain Research employees,
# contractors or other outside parties that have executed Confidentiality
# and/or Non-disclosure agreements explicitly covering such access.
#
# The copyright notice above does not evidence any actual or intended
# publication or disclosure of this source code, which includes information
# that is confidential and/or proprietary, and is a trade secret, of Applied
# Brain Research. ANY REPRODUCTION, MODIFICATION, DISTRIBUTION, PUBLIC
# PERFORMANCE, OR PUBLIC DISPLAY OF OR THROUGH USE OF THIS SOURCE CODE WITHOUT
# THE EXPRESS WRITTEN CONSENT OF APPLIED BRAIN RESEARCH IS STRICTLY PROHIBITED,
# AND IN VIOLATION OF APPLICABLE LAWS AND INTERNATIONAL TREATIES. THE RECEIPT
# OR POSSESSION OF THIS SOURCE CODE AND/OR RELATED INFORMATION DOES NOT CONVEY
# OR IMPLY ANY RIGHTS TO REPRODUCE, DISCLOSE OR DISTRIBUTE ITS CONTENTS, OR TO
# MANUFACTURE, USE, OR SELL ANYTHING THAT IT MAY DESCRIBE, IN WHOLE OR IN PART.

# Automatically generated by abr-bones, do not edit this file directly
"""ABR SDK version management."""

import subprocess
from functools import cache
from pathlib import Path


@cache
def _get_version() -> str:
    """Get the version string for this package."""
    # Semver mode - use configured version + git hash
    version_ = "0.1.0"
    return version_


def _get_git_version(hash_only: bool = False) -> str | None:
    """
    Get version from git repository if available.

    Parameters
    ----------
    hash_only : bool
        If True, return only the git hash suffix (g<short-hash>).
        If False, return full calver version (YY.MM.DD+g<short-hash>).
    """
    # Get version from git - either full date+hash or just hash
    format_string = "g%h" if hash_only else "%cd+g%h"
    try:
        result = subprocess.run(
            [
                "git",
                "show",
                "-s",
                f"--format={format_string}",
                "--date=format:%-y.%-m.%-d",
            ],
            capture_output=True,
            text=True,
            timeout=5,
            check=True,
            cwd=Path(__file__).parent,
        )
        return result.stdout.strip()
    except (
        subprocess.CalledProcessError,
        FileNotFoundError,
        subprocess.TimeoutExpired,
    ):  # pragma: no cover
        return None


version = __version__ = _get_version()
copyright = __copyright__ = "Copyright (c) 2026 Applied Brain Research"
