"""
Version information for MarkiTect.

This module provides version information using setuptools-scm.
Version is automatically derived from git tags.
"""

try:
    from ._version import version as __version__
except ImportError:
    # Fallback when _version.py is not available (e.g., during development without setuptools-scm)
    __version__ = "unknown"

def get_version():
    """Get the current version string."""
    return __version__

def get_version_info():
    """Get comprehensive version information by delegating to release-management capability."""
    try:
        # Delegate to release-management capability
        from pathlib import Path
        project_root = Path(__file__).parent.parent

        try:
            from release_management.utils.version import get_version_info as rm_get_version_info
            return rm_get_version_info(project_root)
        except ImportError:
            # Fallback if release-management capability is not available
            pass
    except Exception:
        pass

    # Simple fallback implementation
    try:
        from ._version import version_tuple, commit_id
    except ImportError:
        version_tuple = ("unknown",)
        commit_id = "unknown"

    return {
        'full_version': __version__,
        'short_version': __version__.split('.dev')[0] if '.dev' in __version__ else __version__,
        'version_tuple': version_tuple,
        'commit_id': commit_id,
        'is_dev': '.dev' in __version__,
        'git_commit': commit_id,
        'git_branch': 'unknown',
        'is_git_repo': False
    }

def get_release_info():
    """Get release information by delegating to release-management capability."""
    try:
        # Delegate to release-management capability
        from pathlib import Path
        project_root = Path(__file__).parent.parent

        try:
            from release_management.utils.version import get_release_info as rm_get_release_info
            return rm_get_release_info(project_root)
        except ImportError:
            # Fallback if release-management capability is not available
            pass
    except Exception:
        pass

    # Simple fallback implementation
    from datetime import datetime
    version_info = get_version_info()

    return {
        'name': 'MarkiTect',
        'version': version_info['full_version'],
        'short_version': version_info['short_version'],
        'is_development': version_info['is_dev'],
        'git_branch': version_info.get('git_branch', 'unknown'),
        'git_commit': version_info.get('git_commit', 'unknown'),
        'build_date': datetime.now().isoformat(),
        'python_version': f"{__import__('sys').version_info.major}.{__import__('sys').version_info.minor}.{__import__('sys').version_info.micro}"
    }