import re


def to_seconds(value: str) -> int:
    """Convert time unit given as '<int> <s|m|h|d>` to seconds.
    :param value: input str
    :type value: str
    :raises ValueError: value must be given as '<int> <s|m|h|d>
    :raises ValueError: value must be > 0s
    :return: value given in seconds
    :rtype: int
    """

    value = value.strip()
    pattern = re.compile(r"\d+ *[sSmMhHdD]")
    if not pattern.fullmatch(value):
        raise ValueError(
            "invalid interval: {}, interval must be given as '<int> <s|m|h|d>'".format(
                value
            )
        )

    num = int(value[0 : len(value) - 1])
    unit = value[-1].lower()

    as_seconds = {"s": 1, "m": 60, "h": 60 * 60, "d": 60 * 60 * 24}

    result = as_seconds[unit] * num

    if result <= 0:
        raise ValueError(
            "invalid interval: {}, interval must be greater than 0 seconds".format(
                result
            )
        )

    return result