#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName: ModuleLevel.py
 @DateTime: 2025/4/8 20:12
 @SoftWare: PyCharm
 @Author  ：xsh
"""
class AxisLevel(int):
    AxisUnknown     : int = -1
    AxisP           : int = 0
    AxisX           : int = 1
    AxisY           : int = 2
    AxisZ           : int = 3
    AxisH           : int = 4
    AxisR           : int = 5
    AxisG           : int = 6
    ModBus          : int = 7
    ModBusDetection : int = 8
    ScanX           : int = 9
    ScanY           : int = 10
    SlowScanX       : int = 11
    SlowScanY       : int = 12
    DropOilX        : int = 13
    DropOilY        : int = 14
    Detection       : int = 15
    @classmethod
    def all(cls) -> list[int]:
        return [
            cls.AxisUnknown     ,
            cls.AxisP           ,
            cls.AxisX           ,
            cls.AxisY           ,
            cls.AxisZ           ,
            cls.AxisH           ,
            cls.AxisR           ,
            cls.AxisG           ,
            cls.ModBus          ,
            cls.ModBusDetection ,
            cls.ScanX           ,
            cls.ScanY           ,
            cls.SlowScanX       ,
            cls.SlowScanY       ,
            cls.DropOilX        ,
            cls.DropOilY        ,
            cls.Detection       ,
        ]

    @classmethod
    def all_axis(cls) -> list[int]:
        return [
            cls.AxisX           ,
            cls.AxisY           ,
            cls.AxisZ           ,
            cls.ScanX           ,
            cls.ScanY           ,
            cls.SlowScanX       ,
            cls.SlowScanY       ,
            cls.DropOilX        ,
            cls.DropOilY        ,
        ]

    @classmethod
    def AxisScanning(cls) -> list[int]:
        return [
            cls.AxisX           ,
            cls.AxisY           ,
            cls.ScanX           ,
            cls.ScanY           ,
            cls.ScanX           ,
            cls.ScanY           ,
            cls.SlowScanX       ,
            cls.SlowScanY       ,
        ]
    @staticmethod
    def toList() -> list[int]:
        return [
            AxisLevel.AxisUnknown     ,
            AxisLevel.AxisP           ,
            AxisLevel.AxisX           ,
            AxisLevel.AxisY           ,
            AxisLevel.AxisZ           ,
            AxisLevel.AxisH           ,
            AxisLevel.AxisR           ,
            AxisLevel.AxisG           ,
            AxisLevel.ModBus          ,
            AxisLevel.ModBusDetection ,
            AxisLevel.ScanX           ,
            AxisLevel.ScanY           ,
            AxisLevel.SlowScanX       ,
            AxisLevel.SlowScanY       ,
            AxisLevel.DropOilX        ,
            AxisLevel.DropOilY        ,
            AxisLevel.Detection       ,
        ]

    @classmethod
    def isAxis(cls, level: int):
        return isinstance(level, int) and level in [cls.AxisX, cls.AxisY, cls.AxisZ]

    @classmethod
    def isDetector(cls, level):
        return isinstance(level, int) and level == cls.Detection

    @classmethod
    def isScan(cls, level: int):
        return isinstance(level, int) and level in [cls.ScanX, cls.ScanY]

    @classmethod
    def isSlow(cls, level: int):
        return isinstance(level, int) and level in [cls.SlowScanX, cls.SlowScanY]

    @classmethod
    def isDropOil(cls, level: int):
        return isinstance(level, int) and level in [cls.DropOilX, cls.DropOilY]

    @classmethod
    def isAxisH(cls, level):
        return isinstance(level, int) and level in [cls.AxisH]

    @classmethod
    def isAxisZ(cls, level):
        return isinstance(level, int) and level in [cls.AxisZ]

    @staticmethod
    def toHitBotItem() -> dict[str, object]:
        return {
            'AxisX'         : AxisLevel.AxisX       ,
            'AxisY'         : AxisLevel.AxisY       ,
            'AxisZ'         : AxisLevel.AxisZ       ,
            'AxisR'         : AxisLevel.AxisR       ,
            'ScanX'         : AxisLevel.ScanX       ,
            'ScanY'         : AxisLevel.ScanY       ,
            'SlowScanX'     : AxisLevel.SlowScanX   ,
            'SlowScanY'     : AxisLevel.SlowScanY   ,
            'DropOilX'      : AxisLevel.DropOilX    ,
            'DropOilY'      : AxisLevel.DropOilY    ,
            'None'          : None
        }

    @staticmethod
    def toHitBotString(value: int) -> str:
        results: list[str] = [k for k, v in AxisLevel.toHitBotItem().items() if v == value]
        return 'None' if len(results) <= 0 else results[0]

    @staticmethod
    def exists(value: int) -> bool:
        return AxisLevel.toList().index(value) >= 0


class ModuleLevel:
    ModuleUnknown       = -1
    ModuleTray          = 0
    ModuleTraySlide1    = 1
    ModuleTraySlide2    = 2
    ModuleTraySlide3    = 3
    ModuleMicroscope    = 3
    ModuleHitBot        = 4


    @staticmethod
    def toList() -> list[int]:
        return [
            ModuleLevel.ModuleUnknown       ,
            ModuleLevel.ModuleTray          ,
            ModuleLevel.ModuleMicroscope    ,
            ModuleLevel.ModuleHitBot        ,
            ModuleLevel.ModuleTraySlide1    ,
            ModuleLevel.ModuleTraySlide2    ,
        ]
    @staticmethod
    def exists(value: int) -> bool:
        return ModuleLevel.toList().index(value) >= 0

    @classmethod
    def trays(cls) -> list[int]:
        return [cls.ModuleTraySlide1, cls.ModuleTraySlide2, cls.ModuleTraySlide3]

    @classmethod
    def getTrayNumber(cls, level: int):
        try:
            return cls.ModuleTraySlide2 if level == cls.ModuleTraySlide2 else cls.ModuleTraySlide1
        except Exception as e:
            return cls.ModuleTraySlide1



class TrayLevel(int):
    TraySlide1 = 1
    TraySlide2 = 2
    TraySlide3 = 3
    TraySlide4 = 4
    TraySlide5 = 5
    PickTray   = 6
    DropTray   = 7

    @classmethod
    def all(cls) -> list:
        return [
            cls.TraySlide1,
            cls.TraySlide2,
            cls.TraySlide3,
            cls.TraySlide4,
            cls.TraySlide5,
        ]

    @classmethod
    def exists(cls, value) -> bool:
        return isinstance(value, int) and value in cls.all()

    @classmethod
    def getTrayNumber(cls, level: int) -> int:
        return level if cls.exists(level) else cls.TraySlide1

