from dataclasses import dataclass
from typing import Sequence



@dataclass(frozen=True)
class _Types:
    any: str = 'any'

    trace: str = 'trace'
    debug: str = 'debug'
    info: str = 'info'
    warning: str = 'warning'
    error: str = 'error'


    @staticmethod
    def all_levels() -> Sequence[str]:
        return _Types.trace, _Types.debug, _Types.info, _Types.warning, _Types.error


    @staticmethod
    def types2str(types: Sequence[str]|str = None) -> str|None:
        if types is None:
            types = (_Types.info, _Types.error)

        if isinstance(types, str):
            return (
                types.strip('|')
                if f'|{_Types.any}|' not in f'|{types}|'
                else '|'.join(_Types.all_levels())
            )
        elif isinstance(types, (tuple, list)):
            return (
                '|'.join(types)
                if _Types.any not in types
                else '|'.join(_Types.all_levels())
            )
        return None


    @staticmethod
    def types2tuple(types: Sequence[str]|str = None) -> tuple[str,...]|None:
        if types is None:
            types = (_Types.info, _Types.error)

        if isinstance(types, str):
            return tuple(
                i
                for i in (
                    types.strip('|').split('|')
                    if f'|{_Types.any}|' not in f'|{types}|'
                    else _Types.all_levels()
                )
                if i  # fix: empty str removed
            )
        elif isinstance(types, tuple):
            return (
                types
                if _Types.any not in types
                else _Types.all_levels()
            )
        elif isinstance(types, list):
            return (
                tuple(types)
                if _Types.any not in types
                else _Types.all_levels()
            )
        return None

    pass


Types = _Types()
