# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/00_decs.ipynb.

# %% auto 0
__all__ = ['set_fbmem', 'set_attr', 'set_default', 'set_fallback', 'set_method', 'set_dtype', 'set_repr']

# %% ../nbs/00_decs.ipynb 4
from enum import Enum, StrEnum, EnumMeta, auto
from typing import Optional, Any, Callable

# %% ../nbs/00_decs.ipynb 6
def set_attr(
    attr: str, 
    value: Optional[Any] = None,
    is_private: Optional[bool] = True
):
    """
    A decorator to set any attr of a class.

    Parameters
    ----------
    attr : str 
        The attribute to change value.

    value : Any, default: None
        The value to set the attribute to, by default None.

    is_private : bool, default: True
        Whether the attribute should be private or not, by default True.
        If True, the attribute will be prefixed with an underscore.
    
    Returns
    -------
    cls : type    
        The decorated class with the attribute set.
    """
    def wrapper(cls):
        prefix = '_' if is_private else ''
        attr_name = f'{prefix}{attr}'
        setattr(cls, attr_name, value)
        return cls
    return wrapper

# %% ../nbs/00_decs.ipynb 10
def set_default(default: str = ''):
    """
    A decorator to set the default member for a class.

    Parameters
    ----------    
    default : str, default: ''
        The default value for `_default`
    
    Returns
    -------
    cls : type    
        The decorated class with the `_default` attribute set.

    See Also
    --------
    set_attr : Sets an attribute for a class.
    """
    return set_attr(attr='default', value=default)

# %% ../nbs/00_decs.ipynb 13
def set_fallback(fbmem):
    """
    A decorator to set the default member for a class.

    Parameters
    ----------    
    fbmem : str
        The default fallback member or member name.
    
    Returns
    -------
    cls : type    
        The decorated class with the `fbmem` attribute set.

    See Also
    --------
    set_attr : Sets an attribute for a class.
    """
    return set_attr(attr='fbmem', value=fbmem, is_private=False)

set_fbmem = set_fallback

# %% ../nbs/00_decs.ipynb 16
def set_method(method):
    """
    A decorator to set the method attribute for a class.

    Parameters
    ----------    
    method : Callable
        The method to be set.
    
    Returns
    -------
    cls : type    
        The decorated class with the `method` attribute set.

    See Also
    --------
    set_attr : Sets an attribute for a class.
    """
    return set_attr(attr='method', value=method, is_private=False)

# %% ../nbs/00_decs.ipynb 19
def set_dtype(dtype: type):
    """
    A decorator to set the dtype for a class.

    Parameters
    ----------    
    dtype : type
        The dtype to be set.
    
    Returns
    -------
    cls : type    
        The decorated class with the `dtype` attribute set.

    See Also
    --------
    set_attr : Sets an attribute for a class.
    """    
    return set_attr(attr='dtype', value=dtype, is_private=False)

# %% ../nbs/00_decs.ipynb 22
def set_repr(repr_func: Callable):
    """
    A decorator to set the rich repr attributes (html & md) for a LiteralEnum class.

    Parameters
    ----------    
    repr_func : Callable
        The method to be set to `cls._repr_html_` and `cls._repr_markdown_`.
    
    Returns
    -------
    cls : type    
        The decorated class with the `_repr_html_` and `_repr_markdown_` attributes set.

    See Also
    --------
    set_attr : Sets an attribute for a class.
    """    
    def wrapper(cls):
        setattr(cls, '_repr_html_', repr_func)
        setattr(cls, '_repr_markdown_', repr_func)
        return cls
    return wrapper
