# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_enums.ipynb.

# %% auto 0
__all__ = ['ByteUnit']

# %% ../nbs/02_enums.ipynb 5
from enum import auto, StrEnum
from typing import Optional

# %% ../nbs/02_enums.ipynb 7
from pstr.nlit.byte import (B, KB, MB, GB, TB, PB, EB, ZB, YB, )
from pstr.nchr.core import SPACE

# %% ../nbs/02_enums.ipynb 8
from .units import (KILO)
from bytetype.utils import (
    getidx, getexp, getsuf, getnum, format
)

# %% ../nbs/02_enums.ipynb 10
class ByteUnit(StrEnum):
    B  = auto(); KB = auto(); MB = auto(); GB = auto(); TB = auto(); 
    PB = auto(); EB = auto(); ZB = auto(); YB = auto()

    @classmethod
    def units(cls): return [u.name for u in cls]

    @classmethod
    def getidx(cls, size: int = 1, base: int = KILO) -> int:
        return getidx(size, base, cls.units())
    
    @classmethod
    def getexp(cls, size: int = 1, base: int = KILO) -> int:
        return getexp(size, base, cls.units())
    
    @classmethod
    def getsuf(cls, size: int = 1, base: int = KILO) -> int:
        return getsuf(size, base, cls.units())
    
    @classmethod
    def getnum(cls, size: int = 1, base: int = KILO, precision: Optional[int] = 1) -> int:
        return getnum(size, base, precision, cls.units())

    @classmethod
    def format(cls, size: int = 1, base: int = KILO, sep: Optional[str] = SPACE, precision: Optional[int] = 1):
        return format(size, base, sep, precision, cls.units(), )
