#!D:/IDE/anaconda3/envs python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName：PathContext.py\n
 @DateTime: 2025/7/4 15:52\n
 @Author  ：xsh
"""
import sys
from PyQt5                              import Qt
from AppInterfaces.ModelInterface       import ContextModelInterface
from AppCore.Levels                     import *
from AppUtils.utils                     import *
from AppCore.Requests                   import *


class PathContext(ContextModelInterface):
    RootPath                            : str       # 主目录
    Focusing_SavePath                   : str       # 定焦数据保存路径
    Scanning_SavePath                   : str       # 平扫数据保存路径
    Cell_SavePath                       : str       # 低倍数据保存路径
    CellFocusing_SavePath               : str       # 高倍定焦数据路径
    Karyotype_SavePath                  : str       # 高倍数据保存路径
    Aberration_SavePath                 : str       # 高倍数据保存路径
    Micronucleus_SavePath               : str       # 微核数据保存路径
    Image_Format                        : str       # 图片数据格式
    Info_Format                         : str       # 数据信息格式
    Split_no                            : str

    __slots__ = (
        'RootPath'             ,
        'Focusing_SavePath'    ,
        'Scanning_SavePath'    ,
        'Cell_SavePath'        ,
        'CellFocusing_SavePath',
        'Karyotype_SavePath'   ,
        'Aberration_SavePath'  ,
        'Micronucleus_SavePath',
        'Image_Format'         ,
        'Split_no'             ,
        'Info_Format'          ,
    )
    __types__ = (
        str,
        str,
        str,
        str,
        str,
        str,
        str,
        str,
        str,
        str,
    )
    def __init__(self, **args):
        super(PathContext, self).__init__()
        self.initialization("默认数据保存路径")
        self.initParameter(**args)

    def initParameter(self, **args):
        if not isinstance(args, dict) or len(args) <= 0:
            return
        for index, _property in enumerate(self.__slots__):
            setattr(self, _property, AppConvert.ObjectConvert(args.get(_property, getattr(self, _property, None)),
                                                              self.__types__[index]))

    def initValue(self):
        super(PathContext, self).initValue()
        self.RootPath               = 'd:/DeepLearning_data/'
        self.Focusing_SavePath      = 'MidwayData/Focusing'
        self.Scanning_SavePath      = 'MidwayData/Scanning'
        self.Cell_SavePath          = 'MidwayData/Cell'
        self.CellFocusing_SavePath  = 'MidwayData/CellFocusing'
        self.Karyotype_SavePath     = 'Cases'
        self.Micronucleus_SavePath  = 'Micronucleus'
        self.Aberration_SavePath    = 'Aberration'
        self.Image_Format           = 'JPG'
        self.Split_no               = '-'
        self.Info_Format            = 'yaml'

    @property
    def absoluteRootPath(self) -> str:
        return  self.RootPath

    @property
    def imagefmt(self) -> str:
        return 'jpg' if not self.hasImage_Format else self.Image_Format.upper()

    @property
    def split_no(self) -> str:
        return '-' if not self.hasSplit_no else self.Split_no

    def absoluteFocusing_SavePath(self, codeString) -> str:
        return Qt.QFileInfo("{0}/{1}/{2}/".format(self.RootPath, self.Focusing_SavePath, f'{codeString}')).absoluteFilePath()

    def absoluteScanning_SavePath(self, codeString) -> str:
        return Qt.QFileInfo("{0}/{1}/{2}/".format(self.RootPath, self.Scanning_SavePath, f'{codeString}')).absoluteFilePath()

    def absoluteCellFocusing_SavePath(self, codeString) -> str:
        return Qt.QFileInfo("{0}/{1}/{2}/".format(self.RootPath, self.CellFocusing_SavePath, f'{codeString}')).absoluteFilePath()



    def absoluteCell_SavePath(self, codeString) -> str:
        return Qt.QFileInfo("{0}/{1}/{2}/".format(self.RootPath,self.Cell_SavePath, f'{codeString}')).absoluteFilePath()

    def absoluteKaryotype_SavePath(self, codeString) -> str:
        return Qt.QFileInfo("{0}/{1}/{2}/".format(self.RootPath, self.Karyotype_SavePath, f'{codeString}')).absoluteFilePath()

    def absoluteMicronucleus_SavePath(self, codeString) -> str:
        return Qt.QFileInfo( "{0}/{1}/{2}/".format(self.RootPath, self.Micronucleus_SavePath, f'{codeString}')).absoluteFilePath()

    def getAbsoluteRootPath(self, path: str, codeString: str) -> str:
        return Qt.QFileInfo("{0}/{1}/".format(path, f'{codeString}')).absoluteFilePath()

    def getAbsoluteFocusing_SavePath(self, path: str, codeString: str) -> str:
        return Qt.QFileInfo("{0}/{1}/{2}/".format(path, self.Focusing_SavePath, f'{codeString}')).absoluteFilePath()

    def getAbsoluteScanning_SavePath(self, path: str, codeString: str) -> str:
        return Qt.QFileInfo("{0}/{1}/{2}/".format(path, self.Scanning_SavePath, f'{codeString}')).absoluteFilePath()

    def getCellFocusing_SavePath(self, path: str, codeString: str) -> str:
        return Qt.QFileInfo("{0}/{1}/{2}/".format(path,self.CellFocusing_SavePath, f'{codeString}')).absoluteFilePath()

    def getAbsoluteCell_SavePath(self, path: str, codeString: str) -> str:
        return Qt.QFileInfo("{0}/{1}/{2}/".format(path, self.Cell_SavePath, f'{codeString}')).absoluteFilePath()

    def getAbsoluteMicronucleus_SavePath(self, path: str, codeString) -> str:
        return Qt.QFileInfo("{0}/{1}/{2}/".format(path, self.Micronucleus_SavePath, f'{codeString}')).absoluteFilePath()

    def getAbsoluteKaryotype_SavePath(self, path: str, codeString: str) -> str:
        return Qt.QFileInfo("{0}/{1}/{2}/".format(path, self.Karyotype_SavePath, f'{codeString}')).absoluteFilePath()

    def getAbsoluteAberration_SavePath(self, path: str, codeString: str) -> str:
        return Qt.QFileInfo("{0}/{1}/{2}/".format(path, self.Aberration_SavePath, f'{codeString}')).absoluteFilePath()

    def getAbsoluteMicronucleusPath(self, path: str) -> str:
        return Qt.QFileInfo("{0}/{1}/".format(path, self.Micronucleus_SavePath)).absoluteFilePath()

    def getAbsoluteKaryotypePath(self, path: str) -> str:
        return Qt.QFileInfo("{0}/{1}/".format(path, self.Karyotype_SavePath)).absoluteFilePath()

    def getAbsoluteAberrationPath(self, path: str) -> str:
        return Qt.QFileInfo("{0}/{1}/".format(path, self.Aberration_SavePath)).absoluteFilePath()

    @property
    def hasRootPath           (self) -> bool:
        return hasattr(self, 'RootPath'             ) and isinstance(self.RootPath          , str)
    @property
    def hasFocusing_SavePath  (self) -> bool:
        return hasattr(self, 'Focusing_SavePath'    ) and isinstance(self.Focusing_SavePath , str)
    @property
    def hasScanning_SavePath  (self) -> bool:
        return hasattr(self, 'Scanning_SavePath'    ) and isinstance(self.Scanning_SavePath , str)
    @property
    def hasCell_SavePath      (self) -> bool:
        return hasattr(self, 'Cell_SavePath'        ) and isinstance(self.Cell_SavePath     , str)
    @property
    def hasKaryotype_SavePath (self) -> bool:
        return hasattr(self, 'Karyotype_SavePath'   ) and isinstance(self.Karyotype_SavePath, str)

    @property
    def hasMicronucleus_SavePath(self) -> bool:
        return hasattr(self, 'Micronucleus_SavePath') and isinstance(self.Micronucleus_SavePath, str)

    @property
    def hasImage_Format       (self) -> bool:
        return hasattr(self, 'Image_Format'         ) and isinstance(self.Image_Format      , str)

    @property
    def hasSplit_no(self) -> bool:
        return hasattr(self, 'Split_no') and isinstance(self.Split_no, str)
