import asyncio
import functools
import time
from datetime import datetime
from typing import Callable
from zoneinfo import ZoneInfo

# Vietnam timezone constant
VIETNAM_TZ = ZoneInfo("Asia/Ho_Chi_Minh")


def timer(func: Callable) -> Callable:
    @functools.wraps(func)
    async def async_wrapper(*args, **kwargs):
        """Wrapper for async functions."""
        start_time = time.time()
        result = await func(*args, **kwargs)
        end_time = time.time()
        elapsed_time = end_time - start_time
        return result, elapsed_time

    @functools.wraps(func)
    def sync_wrapper(*args, **kwargs):
        """Wrapper for sync functions."""
        start_time = time.time()
        result = func(*args, **kwargs)
        end_time = time.time()
        elapsed_time = end_time - start_time
        return result, elapsed_time

    # Return appropriate wrapper based on function type
    return async_wrapper if asyncio.iscoroutinefunction(func) else sync_wrapper


def get_current_iso_time() -> str:
    """
    Get the current time in Vietnam timezone as ISO format string.
    
    Returns:
        str: Current time in ISO format (e.g., "2024-01-15T10:30:00+07:00")
        
    Examples:
        >>> get_current_iso_time()
        '2024-01-15T10:30:00+07:00'
    """
    local_time = datetime.now(VIETNAM_TZ)
    iso_time = local_time.isoformat()
    return iso_time


def get_current_timestamp() -> float:
    """
    Get the current timestamp in Vietnam timezone.
    
    Returns:
        float: Current timestamp as Unix timestamp
        
    Examples:
        >>> get_current_timestamp()
        1705297800.123456
    """
    local_time = datetime.now(VIETNAM_TZ)
    timestamp = local_time.timestamp()
    return timestamp


def is_time_in_iso_format(timestamp: str) -> bool:
    try:
        datetime.fromisoformat(timestamp)
        return True
    except ValueError:
        return False
