# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/20_enum.ipynb.

# %% auto 0
__all__ = ['PathKind', 'OSType', 'PathLibType']

# %% ../nbs/20_enum.ipynb 5
import os
from enum import Enum, StrEnum
from pathlib import (Path, PosixPath, WindowsPath)

# %% ../nbs/20_enum.ipynb 7
from nlit import DIR, FILE, PATH, NT, POSIX, WINDOWS

# %% ../nbs/20_enum.ipynb 9
#| export


# %% ../nbs/20_enum.ipynb 11
class PathKind(StrEnum):
    DIR  = DIR
    FILE = FILE
    PATH = PATH
    @classmethod
    def kinds(cls) -> set: return set(m.value for m in cls)   

# %% ../nbs/20_enum.ipynb 13
class OSType(StrEnum):
    NT  = NT
    POSIX = POSIX
    WINDOWS = WINDOWS

    def __str__(self) -> str: return str(self.value).casefold()

    @classmethod
    def osname(cls, obj: 'OSType' = os): 
        return str(getattr(obj, 'name', os.name)).casefold()
    
    @classmethod
    def ostype(cls, obj: 'OSType' = os) -> Path: 
        return PosixPath if cls.osname(obj) == POSIX else WindowsPath
    
    @classmethod
    def oscomp(cls, oshave: 'OSType' = None, oswant: 'OSType' = None) -> bool: 
        return str(oshave) == str(cls.ostype(oswant))
    
    @classmethod
    def is_psx(cls, osn: 'OSType' = None) -> bool: return cls.oscomp(cls.ostype(osn), cls.POSIX)

    @classmethod
    def is_wdx(cls, osn: 'OSType' = None) -> bool: return cls.oscomp(cls.ostype(osn), cls.WINDOWS) 

# %% ../nbs/20_enum.ipynb 15
class PathLibType(Enum):
    POSIX = PosixPath
    WINDOWS = WindowsPath
    
    def __str__(self) -> str: return str(self.name).casefold()

    @classmethod
    def addcls(cls, pthcls):
        for member in cls:
            if pthcls in member.value.__bases__: continue
            member.value.__bases__ += (pthcls, )

    @classmethod
    def pthcls(cls, osname: OSType = None) -> Path:
        return PosixPath if OSType.is_psx(osname) else WindowsPath
